find degrees between 2 vectors

   9503   4   0
User Avatar
Member
1143 posts
Joined: April 2017
Offline
Hi!

I'm testing a detail wrangle that should find the angle in degrees between 2 vectors but the result is off. Where's my mistake?

vector v0 = normalize(set(-1,0,-1));
vector vref = set(0,0,-1);

float dot = dot(v0, vref);
float radians = fit(dot, 1, -1, 0, $PI);
float angle = degrees(radians);

f@rotation = angle;

-Olivier

Attachments:
find_degrees_angle_fail.JPG (51.7 KB)

User Avatar
Member
2152 posts
Joined: Sept. 2015
Offline
Dot product alone isn't enough.

In my sample file I've commented on the single line that does it.

The rest you set up differently to however it works for you.

Attachments:
Angle Between Two Vectors v1.hiplc (70.8 KB)

User Avatar
Member
1143 posts
Joined: April 2017
Offline
Ah!

So I had to do this:

vector v0 = normalize(set(-1,0,-1));
vector vref = set(0,0,-1);

float radians = acos(dot(v0, vref));
float angle = degrees(radians);

Thanks!

-Olivier
User Avatar
Member
23 posts
Joined: July 2015
Offline
In case is helpful..

If you want the rotation value in degrees for each axis component.

vector v0 = normalize(set(-1,0,-1));
vector vref = set(0,0,-1);

vector4 orient = dihedral(v0, vref);
vector angle = qconvert(orient);

angle = degrees(angle)*-1;
v@angle = angle;


You could reference the angle attribute in the rotation parameter of a transformSOP.

tag: rotation in degree for each axis component from direction vectors
User Avatar
Member
9249 posts
Joined: July 2007
Offline
wlvl
If you want the rotation value in degrees for each axis component.
...
vector angle = qconvert(orient);
angle = degrees(angle)*-1;
...

that doesn't sound correct
qconvert() will convert quaternion to angle/axis vector representation and that's different from per axis euler angles
to get actual euler angles you'll need to use quaterniontoeuler instead
...
vector angle = quaterniontoeuler(orient, 0);
angle = degrees(angle);
...
Edited by tamte - March 29, 2020 11:59:07
Tomas Slancik
CG Supervisor
Framestore, NY
  • Quick Links