Adding rotation to points

   11281   5   2
User Avatar
Member
21 posts
Joined: April 2018
Offline
Hi

So far I've only found solutions to just setting the orientation directly but that overrides the pre-existing orient. I need it to be additive.

I'm trying to add primitives to corner points of a box however they are all facing the wrong angle by +45 degrees so I would like to rotate them by -45 degrees.

using this in a wrangle rotates them fine but it is not additive.
 vector axis;
 axis = {0,1,0};
 axis = normalize(axis);
 axis *= radians(0);
 
 @orient = quaternion(axis);
Is there some vex expression I could sample the current orients with before performing my adjustment?

Edited by jimonions - July 13, 2020 21:45:07
User Avatar
Member
404 posts
Joined: April 2017
Offline
You can accumulate orientations by multiplying them together.

vector axis = {0,1,0};
float angle = radians(45);
vector4 add_rotate = quaternion(angle, axis);
p@orient = qmultiply(p@orient, add_rotate);

Might need to switch the terms around in the qmultiply() function to get the order right, but otherwise if your points already have a valid orientation this should work.
MOPs (Motion Operators for Houdini): http://www.motionoperators.com [www.motionoperators.com]
User Avatar
Member
21 posts
Joined: April 2018
Offline
I'm guessing my points don't have proper orientation.
Simply creating a vector 4 orient attribute doesnt retain those N values. Trying to do a transfer attribute doesnt seem to work as it just changes the type into a vector 3.
Is this because the transferred attribute is a vector 3 rather than 4? if so how should I go about transferring those N values into a valid vector 4.

I'm not sure where to proceed from here.
Edited by jimonions - July 13, 2020 23:41:33
User Avatar
Member
404 posts
Joined: April 2017
Offline
Apologies in advance for the math lesson…

Orientation can only be described by, at minimum, a pair of vectors: one vector is the “forward” axis, which in Houdini typically means the normal, and the other vector is the “up” axis. If you've ever used Copy to Points, you're probably familiar with the need to set those attributes in order to orient your copies.

The reason you need two vectors is so that you can cross-multiply them to get a third orthogonal vector. Those three vectors become a 3x3 transform matrix: a set of three vectors that describe the three axes of an object.

Orientation can also be described as a quaternion, which is a four-dimensional vector that's a kind of weird mathematical hack that makes it simpler to blend between orientations.

Long story short, you need to define what the orientation of your points is currently, then you can multiply other orientations by it in order to accumulate on top of that. You can create an orientation out of vectors by first using
matrix3 m = maketransform(v1, v2)
to create a transform matrix, then
vector4 q = quaternion(m)
to convert that matrix to a quaternion so it can be multiplied with the other one. One of those vectors, up, can probably be {0,1,0} from the looks of your scene. The other maybe you could get from the point normals? Hard to say without knowing what you mean by the “right” orientation in your case.
Edited by toadstorm - July 13, 2020 23:49:45
MOPs (Motion Operators for Houdini): http://www.motionoperators.com [www.motionoperators.com]
User Avatar
Member
21 posts
Joined: April 2018
Offline
I have a long history of hard times with math.
I've watched a lot of videos and tutorials explaining matrixes and quaternions in the past but I've never succeeded working with them and always have to fallback to a simpler but more time consuming and expensive methods.

Is there some sort of step by step tutorial that could walk me through using matrixes so I can understand it to the point I could tackle it myself? preferably in houdini.
Edited by jimonions - July 14, 2020 01:08:44
User Avatar
Member
18 posts
Joined: Aug. 2018
Offline
jimonions
I have a long history of hard times with math.
I've watched a lot of videos and tutorials explaining matrixes and quaternions in the past but I've never succeeded working with them and always have to fallback to a simpler but more time consuming and expensive methods.

Is there some sort of step by step tutorial that could walk me through using matrixes so I can understand it to the point I could tackle it myself? preferably in houdini.

I know it's late, you can check https://www.youtube.com/c/JunichiroHorikawa [www.youtube.com] for houdini math tutorials
  • Quick Links