List of usage examples for org.apache.commons.math3.complex Quaternion multiply
public Quaternion multiply(final double alpha)
From source file:etomica.virial.MCMoveClusterRingRegrowOrientation.java
public void rotateVectorV(double angle, IVector axis, IVectorMutable v) { double q0 = Math.cos(angle / 2.0); double sth2 = Math.sin(angle / 2.0); IVectorMutable a1 = space.makeVector(); a1.E(axis);/* w w w . jav a2s . co m*/ a1.TE(sth2); double q1 = a1.getX(0); double q2 = a1.getX(1); double q3 = a1.getX(2); Quaternion q = new Quaternion(q0, q1, q2, q3); Quaternion vec = new Quaternion(0, v.getX(0), v.getX(1), v.getX(2)); Quaternion w = q.multiply(vec).multiply(q.getConjugate()); if (Math.abs(w.getScalarPart()) > 1E-10) throw new RuntimeException("Quaternion product is not a vector!"); v.E(w.getVectorPart()); }
From source file:sceneGraph.Rot.java
/** Get the swing rotation and twist rotation for the specified axis. The twist rotation represents the rotation around the * specified axis. The swing rotation represents the rotation of the specified axis itself, which is the rotation around an * axis perpendicular to the specified axis. </p> The swing and twist rotation can be used to reconstruct the original * quaternion: this = swing * twist/*from w w w .j a v a 2s. c o m*/ * * @param axisX the X component of the normalized axis for which to get the swing and twist rotation * @param axisY the Y component of the normalized axis for which to get the swing and twist rotation * @param axisZ the Z component of the normalized axis for which to get the swing and twist rotation * @return an Array of Rot objects. With the first element representing the swing, and the second representing the twist * @see <a href="http://www.euclideanspace.com/maths/geometry/rotations/for/decomposition">calculation</a> */ public Rot[] getSwingTwist(DVector axis) { Quaternion thisQ = new Quaternion(rotation.getQ0(), rotation.getQ1(), rotation.getQ2(), rotation.getQ3()); double d = new DVector(thisQ.getQ1(), thisQ.getQ2(), thisQ.getQ3()).dot(axis); Quaternion twist = new Quaternion(rotation.getQ0(), axis.x * d, axis.y * d, axis.z * d).normalize(); if (d < 0) twist.multiply(-1f); Quaternion swing = twist.getConjugate(); swing = Quaternion.multiply(thisQ, swing); Rot[] result = new Rot[2]; result[0] = new Rot(new Rotation(swing.getQ0(), swing.getQ1(), swing.getQ2(), swing.getQ3(), true)); result[1] = new Rot(new Rotation(twist.getQ0(), twist.getQ1(), twist.getQ2(), twist.getQ3(), true)); return result; }