[Closed] Rotating a Vector using a Quat Value
Quick matrix newbie question: How do you rotate a Matrix3 Normalized Vector with a Quaternian Rotation? Is there a function I’m not finding in the documentation?
I guess another way to ask this is: if I have an object’s rotation (in quat or Euler) and I want to find its local X, Y and Z normalized values how would I go about that?
Quaternions are feely convertible to matrix3 values (documented)
The rotation of a node describes how to rotate the node from world aligned state to get to a specific orientation in world space. To get that orientation, you need the inverse of the matrix3 value of the quat describing the rotation. Then, the .row1, row2 and .row3 components of the resulting matrix are the local X, Y and Z axes of the node, equivalent to the three rows of its node transformation matrix. If the node has scaling, you might want to normalize the vectors.
So,
theRot = $.rotation --the quat value
theTM = theRot as matrix3 --the quat as matrix
theInvTM = invertse theTM --invert the matrix
theX = normalize theInvTM.row1 --grab the X axis
theY = normalize theInvTM.row2 --grab the Y axis
theZ = normalize theInvTM.row3 --grab the Z axis
or shorter
theX = normalize (inverse ($.rotation as matrix3)).row1
theY = normalize (inverse ($.rotation as matrix3)).row2
theZ = normalize (inverse ($.rotation as matrix3)).row3
These are the same as
theX = normalize $.transform.row1
theY = normalize $.transform.row2
theZ = normalize $.transform.row3
For an arbitrary vector, you can just multiply the world space unit vector with the inverted matrix:
[0,0,1] * inverse ($.rotation as matrix3)
This is equivalent to theZ axis from the above examples – this takes the world Z and rotates it using the quat rotation, aligning it to the local Z axis of the object.