Quaternion for Processing

I (and @robbietilton) just needed so I wrote a simple quaternion class that comes in handy when recursively rotating PVectors. The detailed documentation is on GitHub.

GitHub
Download


// usage examples

PVector v = new PVector(1,0,0);
Quaternion q = new Quaternion(radians(30), new PVector(0,0,1)); // rotate 30 degrees around z-axis
v = q.mult(v); // apply rotation to the vector


PVector v2 = new PVector(0,1,0);
Quaternion xRot = new Quaternion(radians(30), new PVector(1,0,0)); // rotate 30 degrees around x-axis
Quaternion yRot = new Quaternion(radians(30), new PVector(0,1,0)); // rotate 30 degrees around y-axis
v2 = xRot.mult(yRot).mult(v2); // apply two rotations to the vector

Related Posts with Thumbnails

Tags:

Leave a Reply

You must be logged in to post a comment.