Skip to main content
gamedev.net
🔒 Locked

Vector Computaion Problem

Started by Dakiar Dec 8, 2005 at 3:23 PM 1 replies 500+ views
Original Post
Dakiar
Dakiar
I have two vectors A, and B and I want to know if I should rotate A clock-wise or counter-clock-wise to reach B as fast as possible. I rotate a ceratin amount of degrees each second. It's enough if it works with 2d vectors, even if a 3d formula would be nice too.. I have a way to compute this but it's very bad.. something beautiful would be very much appriciated!!
Zakwayda
Zakwayda
In 2d you can find the signed angle between vectors of arbitrary non-zero length as:
angle = atan2(perpDot(a,b),dot(a,b));
In 3d you can find the unsigned angle as:
angle = atan2(length(cross(a,b)),dot(a,b));
To give the angle a sign in 3d, you need a reference vector; the sign of the angle is then the sign of the dot product of cross(a,b) with this reference vector. What makes sense to use as a reference vector depends on the circumstance.
Dakiar
Dakiar
Thank you so much, you've made my big bunch of code into a beautiful one-liner :D

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.