/** * Subtracts the double components of another quaternion from this one. * * @param x The x (imaginary) component of the quaternion to subtract * @param y The y (imaginary) component of the quaternion to subtract * @param z The z (imaginary) component of the quaternion to subtract * @param w The w (real) component of the quaternion to subtract * @return A new quaternion, which is the difference of both */ public Quaterniond sub(double x, double y, double z, double w) { return new Quaterniond(this.x - x, this.y - y, this.z - z, this.w - w); }
/** * Adds the double components of another quaternion to this one. * * @param x The x (imaginary) component of the quaternion to add * @param y The y (imaginary) component of the quaternion to add * @param z The z (imaginary) component of the quaternion to add * @param w The w (real) component of the quaternion to add * @return A new quaternion, which is the sum of both */ public Quaterniond add(double x, double y, double z, double w) { return new Quaterniond(this.x + x, this.y + y, this.z + z, this.w + w); }
/** * Conjugates the quaternion. <br> Conjugation of a quaternion <code>a</code> is an operation returning quaternion <code>a'</code> such that <code>a' * a = a * a' = |a|<sup>2</sup></code> where * <code>|a|<sup>2<sup/></code> is squared length of <code>a</code>. * * @return the conjugated quaternion */ @Override public Quaterniond conjugate() { return new Quaterniond(-x, -y, -z, w); }
/** * Conjugates the quaternion. <br> Conjugation of a quaternion <code>a</code> is an operation returning quaternion <code>a'</code> such that <code>a' * a = a * a' = |a|<sup>2</sup></code> where * <code>|a|<sup>2<sup/></code> is squared length of <code>a</code>. * * @return the conjugated quaternion */ @Override public Quaterniond conjugate() { return new Quaterniond(-x, -y, -z, w); }
/** * Creates a new quaternion from the double real component. * * <p>The {@link #ZERO} constant is re-used when {@code w} is 0.</p> * * @param w The w (real) component * @return The quaternion created from the double real component */ public static Quaterniond fromReal(double w) { return w == 0 ? ZERO : new Quaterniond(0, 0, 0, w); }
/** * Multiplies the components of this quaternion by a double scalar. * * @param a The multiplication scalar * @return A new quaternion, which has each component multiplied by the scalar */ @Override public Quaterniond mul(double a) { return new Quaterniond(x * a, y * a, z * a, w * a); }
/** * Creates a new quaternion from the double real component. * * <p>The {@link #ZERO} constant is re-used when {@code w} is 0.</p> * * @param w The w (real) component * @return The quaternion created from the double real component */ public static Quaterniond fromReal(double w) { return w == 0 ? ZERO : new Quaterniond(0, 0, 0, w); }
/** * Subtracts the double components of another quaternion from this one. * * @param x The x (imaginary) component of the quaternion to subtract * @param y The y (imaginary) component of the quaternion to subtract * @param z The z (imaginary) component of the quaternion to subtract * @param w The w (real) component of the quaternion to subtract * @return A new quaternion, which is the difference of both */ public Quaterniond sub(double x, double y, double z, double w) { return new Quaterniond(this.x - x, this.y - y, this.z - z, this.w - w); }
@Override public Quaterniond clone() { return new Quaterniond(this); }
/** * Divides the components of this quaternion by a double scalar. * * @param a The division scalar * @return A new quaternion, which has each component divided by the scalar */ @Override public Quaterniond div(double a) { return new Quaterniond(x / a, y / a, z / a, w / a); }
/** * Adds the double components of another quaternion to this one. * * @param x The x (imaginary) component of the quaternion to add * @param y The y (imaginary) component of the quaternion to add * @param z The z (imaginary) component of the quaternion to add * @param w The w (real) component of the quaternion to add * @return A new quaternion, which is the sum of both */ public Quaterniond add(double x, double y, double z, double w) { return new Quaterniond(this.x + x, this.y + y, this.z + z, this.w + w); }
/** * Divides the components of this quaternion by a double scalar. * * @param a The division scalar * @return A new quaternion, which has each component divided by the scalar */ @Override public Quaterniond div(double a) { return new Quaterniond(x / a, y / a, z / a, w / a); }
@Override public Quaterniond toDouble() { return new Quaterniond(x, y, z, w); }
/** * Multiplies the components of this quaternion by a double scalar. * * @param a The multiplication scalar * @return A new quaternion, which has each component multiplied by the scalar */ @Override public Quaterniond mul(double a) { return new Quaterniond(x * a, y * a, z * a, w * a); }
@Override public Quaterniond toDouble() { return new Quaterniond(x, y, z, w); }
@Override public Quaterniond toDouble() { return new Quaterniond(x, y, z, w); }
/** * Creates a new quaternion from the double imaginary components. * * <p>The {@link #ZERO} constant is re-used when {@code x}, {@code y}, and {@code z} are 0.</p> * * @param x The x (imaginary) component * @param y The y (imaginary) component * @param z The z (imaginary) component * @return The quaternion created from the double imaginary components */ public static Quaterniond fromImaginary(double x, double y, double z) { return x == 0 && y == 0 && z == 0 ? ZERO : new Quaterniond(x, y, z, 0); }
@Override public Quaterniond toDouble() { return new Quaterniond(x, y, z, w); }
/** * Normalizes this quaternion. * * @return A new quaternion of unit length */ @Override public Quaterniond normalize() { final double length = length(); if (Math.abs(length) < GenericMath.DBL_EPSILON) { throw new ArithmeticException("Cannot normalize the zero quaternion"); } return new Quaterniond(x / length, y / length, z / length, w / length); }
/** * Creates a new quaternion from the rotation double angle in radians around the axis vector double components. * * @param angle The rotation angle in radians * @param x The x component of the axis vector * @param y The y component of the axis vector * @param z The z component of the axis vector * @return The quaternion defined by the rotation around the axis */ public static Quaterniond fromAngleRadAxis(double angle, double x, double y, double z) { final double halfAngle = angle / 2; final double q = TrigMath.sin(halfAngle) / (double) Math.sqrt(x * x + y * y + z * z); return new Quaterniond(x * q, y * q, z * q, TrigMath.cos(halfAngle)); }