angleTo() returning unexpected result for rotated vector

angleTo() returning unexpected result for rotated vector

rajyalakshmi_perla
Observer Observer
163 Views
4 Replies
Message 1 of 5

angleTo() returning unexpected result for rotated vector

rajyalakshmi_perla
Observer
Observer

Hi all,

I'm working with AutoCAD 2025 and the ObjectARX C++ API.

I have the following setup:

  • v1({0.00000, 0.86603, 0.50000}) is the original directional vector.

  • v2({-0.50000, -0.75000, -0.43301}) is v1 after being rotated using the AutoCAD ROTATE command by 150 degrees.

  • v3({0.86603, -0.43301, -0.25000}) is the normal vector (axis of rotation).

I'm using the angleTo() function like this:

double angle = v1.angleTo(v2, v3); // expecting ~150 degrees in radians

 

However, the result I'm getting seems to be 2π - expected angle, i.e., ~210 degrees instead of 150 degrees (in radians).

Is this the expected behavior of angleTo() in certain vector orientations, or am I missing something regarding vector direction or rotation axis?

Would appreciate any clarification or tips on handling this.

Thanks in advance!

0 Likes
164 Views
4 Replies
Replies (4)
Message 2 of 5

Brock_Olly
Collaborator
Collaborator

The function apparently always returns the smallest positive angle between two vectors, measured counterclockwise around the normal vector (v3).
So it loops around the other side

Message 3 of 5

rajyalakshmi_perla
Observer
Observer

Thank you @Brock_Olly  for clarifying how angleTo() works.
In my case though, I want to show the actual rotation angle applied (for example, 150° CCW) in my component properties after using the built-in AutoCAD ROTATE command.

What’s the recommended way to get the actual rotation angle — matching the direction the ROTATE command applied — when I only have the original and rotated vectors and a normal vector?

0 Likes
Message 4 of 5

Brock_Olly
Collaborator
Collaborator

Since I only have autocad LT for the time being I cannot test it but you can try this:

 

AcGeVector3d v1 = ...; // original vector
AcGeVector3d v2 = ...; // rotated vector
AcGeVector3d v3 = ...; // normal (rotation axis)

double angle = v1.angleTo(v2, v3); // always in [0, 2π)
double sign = v1.crossProduct(v2).dotProduct(v3) >= 0 ? 1.0 : -1.0;
double signedAngle = sign * angle;

 

 

0 Likes
Message 5 of 5

rajyalakshmi_perla
Observer
Observer

Thank you, it’s really helpful! I tried suggested approach, but even with this I'm getting sign as negative only

0 Likes