how to calculate and apply orientation offset points

   3128   8   2
User Avatar
Member
81 posts
Joined: Feb. 2014
Offline
Hi
I am trying to find a method to calculate the difference in rotation/orientation between point A and B, and add that difference/offset to the existing orientation of point C.

What would be the most elegant way?

Thanks
Michiel
User Avatar
Member
359 posts
Joined: April 2017
Offline
Assuming you have the orientations of your A and B points stored as quaternions or matrix3's, you can find the “difference” between them by inverting the orientation of A and multiplying it by the orientation of B. Then take that result and multiply it by the existing orientation of C.

// i might be getting the order of operations wrong here, might want to double check
vector4 diff = qmultiply(qinvert(A), B);
vector4 new_C = qmultiply(diff, C);
MOPs (Motion Operators for Houdini): http://www.motionoperators.com [www.motionoperators.com]
User Avatar
Member
81 posts
Joined: Feb. 2014
Offline
Thank you, Toadstorm, I will give that a spin. My nose was already pointing in that direction a bit but to find the proper means through trial and error requires quite some luck. Quaternion multiplication indeed sounds like the logical route. Didn't new matrices could also be qmultiplied.

Cheers
Michiel
User Avatar
Member
359 posts
Joined: April 2017
Offline
Didn't new matrices could also be qmultiplied.

Matrices can just be multiplied using * in VEX… there's no special function for it. Inverting a matrix or matrix3 is done with the invert() function instead of qinvert(). Otherwise the basic idea behind the code is the same.
Edited by toadstorm - Dec. 3, 2019 09:35:10
MOPs (Motion Operators for Houdini): http://www.motionoperators.com [www.motionoperators.com]
User Avatar
Member
81 posts
Joined: Feb. 2014
Offline
That I indeed understand… but more on on a fundamental level I was unaware they are to be combined
User Avatar
Member
475 posts
Joined: July 2005
Online
Hi,

another way to get a rotation matrix, which transform a point A to points B direction, is using the dihedral() function (which works for quaternions and matrices aswell).
The function takes two points as input and returns a rotation matrix as output, which rotates point A to B.
This function looks like, that it takes the cross product of A,B, which is defining an rotation axis (if A,B are not on a line) and the angle, whic can be calculated using the dot product.
Here is an example, where you can use point attributes as multiplier for the angle, which can set in a wrangle.

Attachments:
rotation_from_pointsA.hipnc (91.1 KB)

User Avatar
Member
81 posts
Joined: Feb. 2014
Offline
@Toadstorm: Are you sure matrices can be qmultiplied? Houdini gives me an error “Errors or warnings encountered during VEX compile:
No matching function for vector4 qmultiply(vector4; matrix3). Candidates are: vector4 qmultiply(vector4; vector4)”
. This would in a certain way make sense to me (with my limited grasp of math), since I thought matrices were in the domain of linear algebra and quaternions in the non-linear domain..

@Aizatulin: Thanks for the example. It's a bit overwhelming, I can't yet discover if it would apply to my case. I am looking for a per point-comparison: ((diff orientation between P1 and P2) added to the existing rotation of P3). I do however understand that the dihedral function might apply here..
User Avatar
Member
359 posts
Joined: April 2017
Offline
@Toadstorm: Are you sure matrices can be qmultiplied? Houdini gives me an error

In the last post I said matrices can be multiplied using the * operator, and inverted using invert() instead of qinvert(). You can convert from a matrix3 to a quaternion using quaternion(myMatrix3) if you need to, or go the other way around using qconvert(myVector4).
MOPs (Motion Operators for Houdini): http://www.motionoperators.com [www.motionoperators.com]
User Avatar
Member
475 posts
Joined: July 2005
Online
Here is reduced version of my example using the dihedral() function (using 3 points from the second input). Every point from the first input will be transformed by the rotation matrix.

Attachments:
rotation_from_points.hipnc (80.9 KB)

  • Quick Links