Java Code Examples for org.apache.commons.math3.geometry.euclidean.threed.Rotation#getQ2()

The following examples show how to use org.apache.commons.math3.geometry.euclidean.threed.Rotation#getQ2() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RotationUtil.java    From NOVA-Core with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Returns the slerp interpolation of Rotations {@code a} and {@code b}, at
 * time {@code t}.
 * <p>
 * {@code t} should range in {@code [0,1]}. Result is a when {@code t=0 } and
 * {@code b} when {@code t=1}.
 * <p>
 * When {@code allowFlip} is true (default) the slerp interpolation will
 * always use the "shortest path" between the Rotations' orientations, by
 * "flipping" the source Rotation if needed.
 * @param a the first Rotation
 * @param b the second Rotation
 * @param t the temporal interpolation parameter
 * @param allowFlip tells whether or not the interpolation allows axis flip
 * @return The slerp interpolation of Rotations {@code a} and {@code b}, at time {@code t}.
 */
public static Rotation slerp(Rotation a, Rotation b, double t, boolean allowFlip) {
	// TODO: this method should not normalize the Rotation
	double cosAngle = dotProduct(a, b);

	double c1, c2;
	// Linear interpolation for close orientations
	if ((1.0 - FastMath.abs(cosAngle)) < 0.01) {
		c1 = 1.0f - t;
		c2 = t;
	} else {
		// Spherical interpolation
		double angle = FastMath.acos(FastMath.abs(cosAngle));
		double sinAngle = FastMath.sin(angle);
		c1 = FastMath.sin(angle * (1.0f - t)) / sinAngle;
		c2 = FastMath.sin(angle * t) / sinAngle;
	}

	// Use the shortest path
	if (allowFlip && (cosAngle < 0.0)) {
		c1 = -c1;
	}

	return new Rotation(c1 * a.getQ1() + c2 * b.getQ1(), c1 * a.getQ2() + c2 * b.getQ2(), c1 * a.getQ3()
		+ c2 * b.getQ3(), c1 * a.getQ0() + c2 * b.getQ0(), false);
}
 
Example 2
Source File: RotationUtil.java    From NOVA-Core with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Returns the "dot" product of this Quaternion and {@code b}:
 * <p>
 * {@code this.x * b.x + this.y * b.y + this.z * b.z + this.w * b.w}
 * @param a This
 * @param b the Quaternion
 * @return The dot product
 */
public static double dotProduct(Rotation a, Rotation b) {
	return a.getQ0() * b.getQ0() + a.getQ1() * b.getQ1() + a.getQ2() * b.getQ2() + a.getQ3() * b.getQ3();
}