/** * Set this {@link AxisAngle4d} to the given values. * * @param angle * the angle in radians * @param v * the rotation axis as a {@link Vector3f} * @return this */ public AxisAngle4d set(double angle, Vector3f v) { return set(angle, v.x, v.y, v.z); }
/** * Return a string representation of this {@link AxisAngle4d}. * <p> * This method creates a new {@link DecimalFormat} on every invocation with the format string "<code> 0.000E0;-</code>". * * @return the string representation */ public String toString() { DecimalFormat formatter = new DecimalFormat(" 0.000E0;-"); String str = toString(formatter); StringBuffer res = new StringBuffer(); int eIndex = Integer.MIN_VALUE; for (int i = 0; i < str.length(); i++) { char c = str.charAt(i); if (c == 'E') { eIndex = i; } else if (c == ' ' && eIndex == i - 1) { // workaround Java 1.4 DecimalFormat bug res.append('+'); continue; } else if (Character.isDigit(c) && eIndex == i - 1) { res.append('+'); } res.append(c); } return res.toString(); }
/** * Transform the given vector by the rotation transformation described by this {@link AxisAngle4d}. * * @param v * the vector to transform * @return v */ public Vector4d transform(Vector4d v) { return transform(v, v); }
/** * Set this {@link AxisAngle4d} to be equivalent to the given * {@link Quaterniondc}. * * @param q * the quaternion to set this AngleAxis4d from * @return this */ public AxisAngle4d set(Quaterniondc q) { double acos = safeAcos(q.w()); double invSqrt = 1.0 / Math.sqrt(1.0 - q.w() * q.w()); this.x = q.x() * invSqrt; this.y = q.y() * invSqrt; this.z = q.z() * invSqrt; this.angle = acos + acos; return this; }
@Test public void testMutate() { final Vector3d xAxis = new Vector3d(1, 0, 0); final Vector3d in = new Vector3d(xAxis); final Quaterniond q = new Quaterniond(new AxisAngle4d(Math.PI / 2.0, 0, 0, 1)); final Vector3d expected = xAxis.rotate(q); final Vector3d result = ops.linalg().rotate1(in, q); assertSame("Mutate should operate on the input object", in, result); assertEquals("Rotation is incorrect", expected, result); } }
/** * Set this {@link AxisAngle4d} to be equivalent to the given * {@link Quaternionfc}. * * @param q * the quaternion to set this AngleAxis4d from * @return this */ public AxisAngle4d set(Quaternionfc q) { double acos = safeAcos(q.w()); double invSqrt = 1.0 / Math.sqrt(1.0 - q.w() * q.w()); this.x = q.x() * invSqrt; this.y = q.y() * invSqrt; this.z = q.z() * invSqrt; this.angle = acos + acos; return this; }
@Test public void testAxisAngle() { final Vector3d xAxis = new Vector3d(1, 0, 0); final Vector3d in = new Vector3d(xAxis); final AxisAngle4d axisAngle = new AxisAngle4d(Math.PI / 2.0, 0, 0, 1); final Vector3d expected = xAxis.rotate(new Quaterniond(axisAngle)); final Vector3d result = ops.linalg().rotate(in, axisAngle); assertEquals("Rotation is incorrect", expected, result); }
/** * Create a new {@link AxisAngle4d} from the given {@link Quaternionfc}. * <p> * Reference: <a href= * "http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/" * >http://www.euclideanspace.com</a> * * @param q * the quaternion from which to create the new AngleAxis4f */ public AxisAngle4d(Quaternionfc q) { double acos = safeAcos(q.w()); double invSqrt = 1.0 / Math.sqrt(1.0 - q.w() * q.w()); x = q.x() * invSqrt; y = q.y() * invSqrt; z = q.z() * invSqrt; angle = acos + acos; }
/** * Set this {@link AxisAngle4d} to the given values. * * @param angle * the angle in radians * @param v * the rotation axis as a {@link Vector3f} * @return this */ public AxisAngle4d set(double angle, Vector3f v) { return set(angle, v.x, v.y, v.z); }
/** * Transform the given vector by the rotation transformation described by this {@link AxisAngle4d}. * * @param v * the vector to transform * @return v */ public Vector3d transform(Vector3d v) { return transform(v, v); }
/** * Return a string representation of this {@link AxisAngle4d}. * <p> * This method creates a new {@link DecimalFormat} on every invocation with the format string "<code> 0.000E0;-</code>". * * @return the string representation */ public String toString() { DecimalFormat formatter = new DecimalFormat(" 0.000E0;-"); String str = toString(formatter); StringBuffer res = new StringBuffer(); int eIndex = Integer.MIN_VALUE; for (int i = 0; i < str.length(); i++) { char c = str.charAt(i); if (c == 'E') { eIndex = i; } else if (c == ' ' && eIndex == i - 1) { // workaround Java 1.4 DecimalFormat bug res.append('+'); continue; } else if (Character.isDigit(c) && eIndex == i - 1) { res.append('+'); } res.append(c); } return res.toString(); }
/** * Set this {@link AxisAngle4d} to be equivalent to the given * {@link Quaterniondc}. * * @param q * the quaternion to set this AngleAxis4d from * @return this */ public AxisAngle4d set(Quaterniondc q) { double acos = safeAcos(q.w()); double invSqrt = 1.0 / Math.sqrt(1.0 - q.w() * q.w()); this.x = q.x() * invSqrt; this.y = q.y() * invSqrt; this.z = q.z() * invSqrt; this.angle = acos + acos; return this; }
public AxisAngle4d getRotation(AxisAngle4d dest) { return dest.set(this); }
/** * Transform the given vector by the rotation transformation described by this {@link AxisAngle4d}. * * @param v * the vector to transform * @return v */ public Vector3d transform(Vector3d v) { return transform(v, v); }
/** * Set this {@link AxisAngle4d} to be equivalent to the given * {@link Quaternionfc}. * * @param q * the quaternion to set this AngleAxis4d from * @return this */ public AxisAngle4d set(Quaternionfc q) { double acos = safeAcos(q.w()); double invSqrt = 1.0 / Math.sqrt(1.0 - q.w() * q.w()); this.x = q.x() * invSqrt; this.y = q.y() * invSqrt; this.z = q.z() * invSqrt; this.angle = acos + acos; return this; }
public AxisAngle4d getRotation(AxisAngle4d dest) { return dest.set(this); }
/** * Transform the given vector by the rotation transformation described by this {@link AxisAngle4d}. * * @param v * the vector to transform * @return v */ public Vector3f transform(Vector3f v) { return transform(v, v); }
/** * Create a new {@link AxisAngle4d} from the given {@link Quaterniondc}. * <p> * Reference: <a href= * "http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/" * >http://www.euclideanspace.com</a> * * @param q * the quaternion from which to create the new AngleAxis4d */ public AxisAngle4d(Quaterniondc q) { double acos = safeAcos(q.w()); double invSqrt = 1.0 / Math.sqrt(1.0 - q.w() * q.w()); x = q.x() * invSqrt; y = q.y() * invSqrt; z = q.z() * invSqrt; angle = acos + acos; }
public AxisAngle4d getRotation(AxisAngle4d dest) { return dest.set(this); }
/** * Transform the given vector by the rotation transformation described by this {@link AxisAngle4d}. * * @param v * the vector to transform * @return v */ public Vector3f transform(Vector3f v) { return transform(v, v); }