up/N orient info to quaternion
3131 10 0- element33
- Member
- 76 posts
- Joined: Jan. 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 - March 24, 2022 06:03:40
- animatrix_
- Member
- 4626 posts
- Joined: Feb. 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 | pragmaticvfx.gumroad.com
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]
youtube.com/@pragmaticvfx | patreon.com/animatrix | pragmaticvfx.gumroad.com
- mestela
- Member
- 1768 posts
- Joined: May 2006
- Online
- mestela
- Member
- 1768 posts
- Joined: May 2006
- Online
- element33
- Member
- 76 posts
- Joined: Jan. 2015
- Offline
- tamte
- Member
- 8736 posts
- Joined: July 2007
- Offline
- element33
- Member
- 76 posts
- Joined: Jan. 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 - March 29, 2022 13:13:43
- tamte
- Member
- 8736 posts
- Joined: July 2007
- Offline
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
- 76 posts
- Joined: Jan. 2015
- Offline
- element33
- Member
- 76 posts
- Joined: Jan. 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
- 76 posts
- Joined: Jan. 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