setting @orient with degrees

   4172   4   2
User Avatar
Member
339 posts
Joined: Dec. 2014
Offline
I'm wondering what the best way to go about using degrees to set @orient, here's what I have:

vector4 x_rot = quaternion({1,0,0}*ch('x_rot'));
vector4 y_rot = quaternion({0,1,0}*ch('y_rot'));
vector4 z_rot = quaternion({0,0,1}*ch('z_rot'));

@orient = qmultiply(@orient, x_rot);
@orient = qmultiply(@orient, y_rot);
@orient = qmultiply(@orient, z_rot);

Which works fine, but setting quaternion values with sliders isn't very intuitive
User Avatar
Member
12 posts
Joined: May 2017
Offline
The function you want is eulertoquaternion [www.sidefx.com]
With that you can do the following assuming you've got your rotations in degrees in a vector parameter:
vector r = chv("rot");
p@orient = eulertoquaternion(radians(r),XFORM_XYZ);
User Avatar
Member
339 posts
Joined: Dec. 2014
Offline
That's the ticket, thanks!
User Avatar
Member
339 posts
Joined: Dec. 2014
Offline
In case this is useful for anyone else, these vex expressions allow me to rotate @orient by degrees, but also set a randomized min and max value for those rotations base on the point number. Min and max sliders should go from -1 to 1 and the rot slider 0-360

float randx = fit01(rand(@ptnum),ch('min_x'),ch('max_x'));
float randy = fit01(rand(@ptnum),ch('min_y'),ch('max_y'));
float randz = fit01(rand(@ptnum),ch('min_z'),ch('max_z'));

float rotx = ch('rot_x')*randx;
float roty = ch('rot_y')*randy;
float rotz = ch('rot_z')*randz;

vector r = set(rotx,roty,rotz);

p@orient = eulertoquaternion(radians(r),XFORM_XYZ);
User Avatar
Member
9 posts
Joined: July 2014
Offline
what I usually do is:

matrix m = qconvert(p@orient);
vector zaxis = set(m.zx, m.zy, m.zz);
vector yaxis = set(m.yx, m.yy, m.yz);
vector xaxis = set(m.xx, m.xy, m.xz);
float amount = radians(degrees);
rotate(matrix, amount , xaxis //chose any axis );
p@orient = quaternion(m); 

to create a new orient with euler angles just start with an identity matrix
Edited by Sergen Eren - March 13, 2019 10:10:26
https://sergeneren.com/ [sergeneren.com]
  • Quick Links