Thank you for the example!
I have a better understanding of what you are trying to do here. You are actually not trying to compute the angle between
target. What you want is the angle between
target - source and the
x coordinate axis. There is no method dedicated to this in nalgebra. Something similar, but outputting a rotation matrix (or quaternion) is implemented for 3D but not for 2D). We will consider adding it for 2D too: I’ve created the issue nalgebra#492.
In the mean time, the heading can be computed in the following way:
// You can use a UnitComplex instead of Rotation2 if you prefer.
let heading = Rotation2::rotation_between(Vector2::x(), &(target - source));
let angle = heading.angle();
// For your second question:
let point = source + (Rotation2::new(angle) * Vector2::x()) * distance;
// Alternatively, if you just store the Rotation2 computed with `rotation_between` to avoid reconstructing it from the angle.
let point = source + (heading * Vector2::x()) * distance;
Also note that you could simply do the following to advance a
source toward the heading:
let dir = (target - source).normalize();
let point = source + dir * distance;