find degrees between 2 vectors
7593
4
0
olivierth
Member
1004 posts
Joined: 4月 2017
Offline
2018年11月15日 17:20
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
2024 posts
Joined: 9月 2015
Offline
2018年11月15日 17:59
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: 4月 2017
Offline
2018年11月15日 19:19
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: 7月 2015
Offline
2020年3月29日 6:49
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
8444 posts
Joined: 7月 2007
Offline
2020年3月29日 11:53
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 - 2020年3月29日 11:59:07
Tomas Slancik FX Supervisor Method Studios, NY