find degrees between 2 vectors
7660
4
0
olivierth
Member
1004 posts
Joined: April 2017
Offline
Nov. 15, 2018 5:20 p.m.
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)
BabaJ
Member
2036 posts
Joined: Sept. 2015
Offline
Nov. 15, 2018 5:59 p.m.
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)
olivierth
Member
1004 posts
Joined: April 2017
Offline
Nov. 15, 2018 7:19 p.m.
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
wlvl
Member
23 posts
Joined: July 2015
Offline
March 29, 2020 6:49 a.m.
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
tamte
Member
8525 posts
Joined: July 2007
Offline
March 29, 2020 11:53 a.m.
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 FX Supervisor Method Studios, NY