up/N orient info to quaternion
2568 10 0- element33
- Member
- 74 posts
- Joined: 1月 2015
- Offline
I have a point. animated in space, whose orientation is defined by its N and up vectors (perpendicular). I need to interpolate between some of its positions, so likely I'll have to use a quaternion. What's the best way to convert up/N orient info into a quaternion? I suppose I can pass a matrix into the quaternion(m) declaration, but how do I get a matrix from up and N?
Edited by element33 - 2022年3月24日 06:03:40
- animatrix_
- Member
- 4458 posts
- Joined: 2月 2012
- Offline
Hi,
You can do something like this:
You can do something like this:
matrix3 m = maketransform ( v@N, v@up ); vector4 q = quaternion ( m );
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]
youtube.com/@pragmaticvfx | patreon.com/animatrix | animatrix2k7.gumroad.com
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]
youtube.com/@pragmaticvfx | patreon.com/animatrix | animatrix2k7.gumroad.com
- mestela
- Member
- 1716 posts
- Joined: 5月 2006
- Offline
- mestela
- Member
- 1716 posts
- Joined: 5月 2006
- Offline
- element33
- Member
- 74 posts
- Joined: 1月 2015
- Offline
- tamte
- Member
- 8449 posts
- Joined: 7月 2007
- Online
- element33
- Member
- 74 posts
- Joined: 1月 2015
- Offline
A quick follow-up: can I extract the third axis (not @up, not @N) from a matrix (or quat) defined this way? Yes, I can do cross(@up,@N) myself, but I wonder if I can get the 3rd axis "for free":
matrix3 m = maketransform ( v@N, v@up ); vector4 q = quaternion ( m ); v@sideways = ? ... // some kind of a get_3rd_axis(m) :)
Edited by element33 - 2022年3月29日 13:13:43
- tamte
- Member
- 8449 posts
- Joined: 7月 2007
- Online
v@x = qrotate(q, {1,0,0});
v@x = {1,0,0} * m;
v@x = set(m.xx, m.xy, m.xz);
but again, make sure your N and up are normalized and also up is not gonna necessarily be exact y axis so you may want to extract that one also if you want all 3 orthogonal vectors
Tomas Slancik
FX Supervisor
Method Studios, NY
FX Supervisor
Method Studios, NY
- element33
- Member
- 74 posts
- Joined: 1月 2015
- Offline
- element33
- Member
- 74 posts
- Joined: 1月 2015
- Offline
One more follow-up I may have to do the @N/@up-to-quaternion conversion in Python (in Houdini), not vex. I assume the relevant Python package is numpy, it seems to have quaternions. Has anyone done this in Python? If so what would be the equivalent of the vex code below, so that the result can be assigned as a Houdini quaternion attribute? What's the appropriate Python variable? A tuple? np.array?
Vex: matrix3 m = maketransform ( v@N, v@up ); vector4 q = quaternion ( m );
Python: up = (0,1,0)# tuple N = (0,0,1)# tuple orient = np.quaternion ( up? N? ) pt.setAttribValue('orient',orient)
- element33
- Member
- 74 posts
- Joined: 1月 2015
- Offline
I just realized I can compile that little snippet of vex, then do hou.runVex()
https://www.sidefx.com/docs/houdini/hom/hou/runVex.html [www.sidefx.com]
https://www.sidefx.com/docs/houdini/hom/hou/runVex.html [www.sidefx.com]
-
- Quick Links