/** * Subtracts a quaternion from the instance. * * @param q Quaternion. * @return the difference between this instance and {@code q}. */ public Quaternion subtract(final Quaternion q) { return subtract(this, q); }
/** * Computes the dot-product of the instance by a quaternion. * * @param q Quaternion. * @return the dot product of this instance and {@code q}. */ public double dotProduct(final Quaternion q) { return dotProduct(this, q); }
/** * Multiply every component in the given complex array by the * given real number. The change is made in place. * * @param f the complex array to be scaled * @param d the real scaling coefficient * @return a reference to the scaled array */ public static Complex[] scaleArray(Complex[] f, double d) { for (int i = 0; i < f.length; i++) { f[i] = new Complex(d * f[i].getReal(), d * f[i].getImaginary()); } return f; }
/** * Performs a division of two complex numbers. * * @param xr real part of the first number * @param xi imaginary part of the first number * @param yr real part of the second number * @param yi imaginary part of the second number * @return result of the complex division */ private Complex cdiv(final double xr, final double xi, final double yr, final double yi) { return new Complex(xr, xi).divide(new Complex(yr, yi)); }
/** * Computes the dot-product of two quaternions. * * @param q1 Quaternion. * @param q2 Quaternion. * @return the dot product of {@code q1} and {@code q2}. */ public static double dotProduct(final Quaternion q1, final Quaternion q2) { return q1.getQ0() * q2.getQ0() + q1.getQ1() * q2.getQ1() + q1.getQ2() * q2.getQ2() + q1.getQ3() * q2.getQ3(); }
/** * Create a complex number given the real and imaginary parts. * * @param realPart Real part. * @param imaginaryPart Imaginary part. * @return a new complex number instance. * @since 1.2 * @see #valueOf(double, double) */ protected Complex createComplex(double realPart, double imaginaryPart) { return new Complex(realPart, imaginaryPart); }
/** * Returns {@code true} iff the values are equal as defined by * {@link #equals(Complex,Complex,int) equals(x, y, 1)}. * * @param x First value (cannot be {@code null}). * @param y Second value (cannot be {@code null}). * @return {@code true} if the values are equal. * * @since 3.3 */ public static boolean equals(Complex x, Complex y) { return equals(x, y, 1); }
/** * Returns the conjugate quaternion of the instance. * * @return the conjugate quaternion */ public Quaternion getConjugate() { return new Quaternion(q0, -q1, -q2, -q3); }
/** * Returns the Hamilton product of the instance by a quaternion. * * @param q Quaternion. * @return the product of this instance with {@code q}, in that order. */ public Quaternion multiply(final Quaternion q) { return multiply(this, q); }
/** * Computes the sum of the instance and another quaternion. * * @param q Quaternion. * @return the sum of this instance and {@code q} */ public Quaternion add(final Quaternion q) { return add(this, q); }
/** * Gets the scalar part of the quaternion. * * @return the scalar part. * @see #getQ0() */ public double getScalarPart() { return getQ0(); }
/** * Resolve the transient fields in a deserialized Complex Object. * Subclasses will need to override {@link #createComplex} to * deserialize properly. * * @return A Complex instance with all fields resolved. * @since 2.0 */ protected final Object readResolve() { return createComplex(real, imaginary); }
/** {@inheritDoc} */ public ComplexField getField() { return ComplexField.getInstance(); }
/** * Computes the sum of two quaternions. * * @param q1 Quaternion. * @param q2 Quaternion. * @return the sum of {@code q1} and {@code q2}. */ public static Quaternion add(final Quaternion q1, final Quaternion q2) { return new Quaternion(q1.getQ0() + q2.getQ0(), q1.getQ1() + q2.getQ1(), q1.getQ2() + q2.getQ2(), q1.getQ3() + q2.getQ3()); }
/** * Multiplies the instance by a scalar. * * @param alpha Scalar factor. * @return a scaled quaternion. */ public Quaternion multiply(final double alpha) { return new Quaternion(alpha * q0, alpha * q1, alpha * q2, alpha * q3); }
/** * Returns a {@code Complex} whose value is {@code (-this)}. * Returns {@code NaN} if either real or imaginary * part of this Complex number is {@code Double.NaN}. * * @return {@code -this}. */ public Complex negate() { if (isNaN) { return NaN; } return createComplex(-real, -imaginary); }
/** * Subtracts two quaternions. * * @param q1 First Quaternion. * @param q2 Second quaternion. * @return the difference between {@code q1} and {@code q2}. */ public static Quaternion subtract(final Quaternion q1, final Quaternion q2) { return new Quaternion(q1.getQ0() - q2.getQ0(), q1.getQ1() - q2.getQ1(), q1.getQ2() - q2.getQ2(), q1.getQ3() - q2.getQ3()); }