Skip to content

kynd/PQuaternion

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

PQuaternion

Simple quaternion class for processing. To use, just copy Quaternion class to your project.

#Usage Example

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

#Reference

Quaternion()

Constructor. Creates an identity quaternion.

Quaternion(float _x, float _y, float _z, float _w)

Constructor. Sets four values of the quaternion.

Quaternion(float angle, PVector axis)

Constructor. Sets rotation from an angle in radians around the given axis.

Quaternion get()

Returns a copy of the quaternion.

Boolean equal(Quaternion q)

Returns true if two quaternions are identical.

void set(float _x, float _y, float _z, float _w)

Sets four values of the quaternion.

void setAngleAxis(float angle, PVector axis)

Sets rotation from an angle in radians around the given axis.

Quaternion conj()

Returns conjugation.

Quaternion mult(float r)

Multiplies by scaler.

Quaternion mult(Quaternion q)

Multiplies two quaternions and returns the result.

PVector mult(PVector v)

Apply rotation to a vector and returns the results.

void normalize()

Normalizes the quaternion.

About

Quaternion for processing

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published