Showing posts with label angle. Show all posts
Showing posts with label angle. Show all posts

Monday 7 October 2024

random spin to particles/packed rigid bodies

stolen from a Toadstorm reply somewhere...

axis might be more finessed than just setting to z as shown.. Same goes for the angle, which I've brute forced to -90 times. Anyway, this will give a bit of spin to your packed rigid bodies


vector axis = set(0,0,1); // the random axis attribute you created

float angle = -90*fit01(rand(@ptnum), -1, 1); // change this to whatever range, in radians

vector4 q = quaternion(angle, axis);

v@w = qconvert(q);


Monday 9 March 2020

Rotation in vex

Rotation round an arbitrary axis, in vex

nicked from Rich Lord's handy notes and scenes - https://www.richlord.com/tools/
Placed here, jusssst in case it all vanishes!
The general gist is -


  1. define an axis to rotate around
  2. specify the angle of rotation
  3. create an identity matrix
  4. rotate the matrix by the angle, along the axis
  5. multiply the Position of each point by the transformed matrix

Here's the code -
vector axis = normalize(chv("rotate_axis"));
float angle = radians(chf("rotate_angle"));
// create the matrix representing the rotation, and rotate the points
matrix3 m = ident();
rotate(m, angle, axis);
@P *= m;
Be sure to press the create slider/input button!

A separate example Rich provided has the points rotate around a point in space -

The same technique applies, except a little bit of subtraction/addition of the point position (we move the points-to-be-rotated to the position-of-the-rotation-origin first). Pretty useful, as you're probably not just doing everything at the origin :D

Code -
vector rotate_point = chv("rotate_point"); //this is the origin of the rotation
vector axis = normalize(chv("rotate_axis")); //the axis
float angle = radians(chf("rotate_angle")); //the angle of rotation...
// move the points before the rotation
@P -= rotate_point;
// build the matrix that does the rotation and apply it to the points
matrix3 m = ident();
rotate(m, angle, axis);
@P *= m;
// move the points back to their original position
@P += rotate_point;