Sign in to follow this  
NHughes7

Vector Math question

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Cross the two vectors, then use the result as the axis to perform an axis rotation on the front vector with the limited angle.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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


Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this