Atom Posted January 26, 2018 Share Posted January 26, 2018 (edited) How can I modify this code to randomly rotate in all axis? Currently it does rotate randomly around the Y axis. I could make a quat variable for each axis, but how do I combine them into a final @orient? // Randomize rotation. vector nvec = {0,0,0}; vector axis = {0,1,0}; float rand = 0; vector4 quat = {0,0,0,1}; vector4 product = {0,0,0,1}; nvec = normalize(axis); rand = fit01(random(@ptnum),0,360); quat = quaternion(radians(rand), nvec); @orient = qmultiply({0,0,0,1}, quat); Edited January 26, 2018 by Atom Quote Link to comment Share on other sites More sharing options...
f1480187 Posted January 26, 2018 Share Posted January 26, 2018 (edited) @orient = sample_orientation_uniform(rand(@ptnum)); sample_orientation_uniform.hipnc Edited January 26, 2018 by f1480187 1 Quote Link to comment Share on other sites More sharing options...
Atom Posted January 26, 2018 Author Share Posted January 26, 2018 Ah ha, a one liner thank you! So if I wanted a different random seed on each axis I could break the vector apart. float x = rand(@ptnum); float y = rand(@ptnum+311); float z = rand(@ptnum-801); @orient = sample_orientation_uniform(set(x,y,z)); Quote Link to comment Share on other sites More sharing options...
julienmargelin Posted January 26, 2018 Share Posted January 26, 2018 you can try this too // translate rotate scale pivot matrix myTransform= maketransform(0,0,chv("t"),chv("r"),chv("s"),chv("p")); @orient = quaternion(matrix3(myTransform)); 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.