How can I find the angle between two vectors that answer should be between 0 to 2*pi

We have two points on a circle in 3D space, as well as the center point. How can we calculate the angle between the vector from the center to point one and the vector from the center to point two, with the calculation starting from vector one counter-clockwise to vector two? In other words, the angle should be calculated such that if our first vector is from (0,0,0) to (0,-1,0) and the second vector is from (0,0,0) to (0,0,-1), the angle should be 270 degrees or 3*pi/2, not 90 degrees.

 Accepted Answer

This question has been answered several times:
angle-betwen-two-3d-vectors-in-the-range-0-360-degree, angle-between-two-vectors-in-matlab. But you should also have a think about why your question isn't sufficiently well stated - what's the positive direction for your angle and why do you chose that direction?
HTH

9 Comments

But you should also have a think about why your question isn't sufficiently well stated - what's the positive direction for your angle and why do you chose that direction?
How can we calculate the angle between the vector from the center to point one and the vector from the center to point two, with the calculation starting from vector one counter-clockwise to vector two?
Maybe I miss something, but I think the description is unique. Whether you look at the two vectors from above or from below should not change the direction in which the angle is to be measured.
@Torsten, it should. Take your favourite hand look at it from above and take the angle counter-clock-wise from the thumb to the index finger, then look at it from the other side (palm?) and take the counter-clock-wise angle from the thumb to the index finger.
I don't see a difference, but my spatial sense never was that distinct...
The point is you need an independent indicator of angle "direction" for the 360 degree calculation to make sense. E.g. suppose we pick "up" as that direction vector. If you hold your right hand out palm up, and are trying to calculate the angle "from" your thumb "to" your forefinger, you get about 90 degrees using this indicator. But if you turn your hand over with palm down, you will get about -90 degrees. Since the angle "direction" vector is fixed as "up" (and in this case is going out the back of your hand instead of out the palm), the calculation differs.
I see. But it's -270 degrees and 270 degrees, not 90 degrees and 270 degrees you get as result. I think abs(angle) would suffice for the OP.
Angle indicator direction is fixed as "up". Palm up the measurement is +90 degrees. Palm down the measurement is -90 or +270 degrees. I don't follow your reasoning unless you don't have a fixed angle direction indicator.
How can we calculate the angle between the vector from the center to point one and the vector from the center to point two, with the calculation starting from vector one counter-clockwise to vector two?
You still need an independent indicator to define what counter-clockwise means. Otherwise the 0-360 result doesn't make sense. E.g., you can't just pick cross(v1,v2) as this direction since it is not independent. You would always get +90 degrees for the hand example regardless of the hand orientation if you did that. You could pick the initial cross(v1,v2) as the indicator if you had streams of v1's and v2's. That would make sense. But you can't redefine the indicator on the fly this way.
You are right: keeping counterclockwise, the angle changes from 90 to 270 degrees depending on whether you look from above or from below the plane the circle is in.

Sign in to comment.

More Answers (1)

As suggested there you can trya variation like this:
angle=180*atan2(norm(cross(a,b)), dot(a,b))
where a,b are your vectors.

Asked:

on 31 Mar 2023

Commented:

on 31 Mar 2023

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!