# morient in python

## Recommended Posts

Hi. I`m looking for a python equivalent to morient expression function

Edited by Alexey Vanzhula
##### Share on other sites

You would most likely have to build the matrix yourself, fortunately if you already have two axes, as I assume you do to use the morient expression, although I've never used so it I'm not hundred percent on use cases, it shouldn't be too tough.

All you need to do is take the cross product of the two axis vectors which will then give you the third axis and you can build the matrix per component hou.matrix3(X[0], X[1], X[2], Y[0].....,Z[2]).. Houdini uses Row major notation so that should be the proper way to build it.

##### Share on other sites

Thanx !

I have 3 perpendicular vectors and I want to get rotation to that "axis system".
The most simple form to get it is using hou.hscriptVectorExpression to get 3 angles from morient expr.
So I just want to see most elegant (python) way )

EDIT:

```x, y, z = hou.hscriptVectorExpression('''
{
matrix mat=morient(vector3(%f, %f, %f), vector3(%f, %f, %f));
return vector3(explodematrix( mat, "SRT", "XYZ", "RX" ), explodematrix( mat, "SRT", "XYZ", "RY" ), explodematrix( mat, "SRT", "XYZ", "RZ" ));
}''' % (dir_y[0], dir_y[1], dir_y[2], dir_z[0],dir_z[1],dir_z[2]) )```
Edited by Alexey Vanzhula
##### Share on other sites

You could do

euler = matrix3(vector1, vector2, vector3).extractRotates()

That should give you world space to your vectors' space, in Euler angles.

Thanx

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×