Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.apache.commons.math3.geometry.euclidean.threed.Vector3D;
- import org.apache.commons.math3.complex.Quaternion;
- float ang = 0f;
- void setup() {
- size(600, 600, P3D);
- }
- void draw() {
- fill(255);
- //rect(0, 0, width, height);
- translate(width/2, height/2);
- Vector3D pt = new Vector3D(30, 120, 40);
- Quaternion ptQ = new Quaternion(0, pt.getX(), pt.getY(), pt.getZ());
- Vector3D axis = new Vector3D(50, 50, 50);
- Quaternion q = getQuaternionFromAxisAngle(ang, axis);
- Quaternion r = q.multiply(ptQ).multiply(q.getConjugate());
- stroke(255, 0, 0);
- line(0, 0, 0, (float)r.getQ1(), (float)r.getQ2(), (float)r.getQ3());
- ang += .1;
- }
- Quaternion getQuaternionFromAxisAngle(float degAng, Vector3D vec) {
- float radAng = radians(degAng);
- // Here we calculate the sin( theta / 2) once for optimization
- double factor = sin( radAng / 2.0 );
- // Calculate the x, y and z of the quaternion
- double x = vec.getX() * factor;
- double y = vec.getY() * factor;
- double z = vec.getZ() * factor;
- // Calcualte the w value by cos( theta / 2 )
- double w = cos( radAng / 2.0 );
- return (new Quaternion(w, x, y, z)).normalize();
- }
Advertisement
Add Comment
Please, Sign In to add comment