up/N orient info to quaternion

   2640   10   0
User Avatar
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
User Avatar
Member
4495 posts
Joined: 2月 2012
Offline
Hi,

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
User Avatar
Member
1737 posts
Joined: 5月 2006
Online
  @orient = quaternion(maketransform(@N, @up));
http://www.tokeru.com/cgwiki [www.tokeru.com]
https://www.patreon.com/mattestela [www.patreon.com]
User Avatar
Member
1737 posts
Joined: 5月 2006
Online
Ha, damnit, beat me again!
http://www.tokeru.com/cgwiki [www.tokeru.com]
https://www.patreon.com/mattestela [www.patreon.com]
User Avatar
Member
74 posts
Joined: 1月 2015
Offline
Cool, thanks.
User Avatar
Member
8525 posts
Joined: 7月 2007
Offline
make sure both @N and @up are normalized to get expected result
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
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
User Avatar
Member
8525 posts
Joined: 7月 2007
Offline
v@x = qrotate(q, {1,0,0});
or
v@x = {1,0,0} * m;
or
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
User Avatar
Member
74 posts
Joined: 1月 2015
Offline
Sounds good, thanks. Yes, @up and @N are normalized.
User Avatar
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)
User Avatar
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]
  • Quick Links