Vector Math question
I have 2 3D vectors i can calculate the angle between them
and i need to know how to then reduce the angle
vector 1 is the current forward movement of a ship
vector 2 is the direction the ship wants to move in
i want to limit the ship to only turn at lets say 10 degrees
at a time
vector 1 stays constent
so i should only need to recalculate vector 2
thank you in advance for any help provided.
Why not use a more adapted representation of orientation, such as a quaternion or matrix?
Either way, use your transform library to construct a rotation matrix/quaternion for the relevant angle and around the relevant axis, and apply it to the vectors.
Either way, use your transform library to construct a rotation matrix/quaternion for the relevant angle and around the relevant axis, and apply it to the vectors.
Cross the two vectors, then use the result as the axis to perform an axis rotation on the front vector with the limited angle.
Normalize the vectors, get the angle between them, compute min(max_turn_angle/abs(angle), 1), use that as the interpolation factor in a spherical linear interpolation (SLERP) between the direction vectors.
Three good answers. Tell us more about the nature of the problem, so we can decide which method is most suitable.
the problem is really simple i hope. i have a space ship it moves in a strate line until the user selects a new point to go to.
from this scenario we get vector 1 the the direction the ship is moving currently the length of this vector is the speed of the ship. when the user selects a new point we get vector 2 we get the angle between the 2 vectors using the arc cos of the dot product.
then i check to see if the angle is greater then the ships maximum turning ability
if it is then i need to calculate a new vector
equal in length to vector 1 (the speed of the ship)
but heading as close as i will allow the ship to turn towards the point.
this is easy to map in 2d
draw a line from point x = 0 y = 0 to x = 1 y = 0 this is vector 1
user inputs vector 2 at x = 0 y = 1
the max turning ability of the ship is 45deg
the angle between the two vectors is 90 deg
i beleave the puts the vector 3 at 0.7 for x and y
from this scenario we get vector 1 the the direction the ship is moving currently the length of this vector is the speed of the ship. when the user selects a new point we get vector 2 we get the angle between the 2 vectors using the arc cos of the dot product.
then i check to see if the angle is greater then the ships maximum turning ability
if it is then i need to calculate a new vector
equal in length to vector 1 (the speed of the ship)
but heading as close as i will allow the ship to turn towards the point.
this is easy to map in 2d
draw a line from point x = 0 y = 0 to x = 1 y = 0 this is vector 1
user inputs vector 2 at x = 0 y = 1
the max turning ability of the ship is 45deg
the angle between the two vectors is 90 deg
i beleave the puts the vector 3 at 0.7 for x and y
You want to lerp between the two heading vectors, then. I'd recommend a slerp, in this case, for angular uniformity. Convert the old and new heading vectors into quaternions and interpolate them accordingly (D3DXVec3Slerp will come in handy if you're using DirectX).
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement