Jump to content
Atom

[SOLVED]Random Orient All 3-Axis?

Recommended Posts

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 by Atom

Share this post


Link to post
Share on other sites

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));

 

Share this post


Link to post
Share on other sites

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));

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×