/** * Adds a rotation to this transform, in the xy plane, around the origin and * returns it as a new transform. The rotation is given is quarter turns. * The actual rotation is {@code quarterTurns * 90}. The rotation is around * the block center, not the corner. * * @param quarterTurns The number of quarter turns in this rotation * @return The rotated transform as a copy */ public DiscreteTransform2 withRotation(int quarterTurns) { return new DiscreteTransform2(this.matrix.rotate(Complexd.fromAngleDeg(quarterTurns * 90))); }
/** * Multiplies the double components of another complex with this one. * * @param x The x (real) component of the complex to multiply with * @param y The y (imaginary) component of the complex to multiply with * @return A new complex, which is the product of both */ public Complexd mul(double x, double y) { return new Complexd( this.x * x - this.y * y, this.x * y + this.y * x); }
/** * Returns the inverse of this complex. <br> Inversion of a complex <code>a</code> returns complex <code>a<sup>-1</sup> = a' / |a|<sup>2</sup></code> where <code>a'</code> is {@link #conjugate() * conjugation} of <code>a</code>, and <code>|a|<sup>2</sup></code> is squared length of <code>a</code>. <br> For any complexes <code>a, b, c</code>, such that <code>a * b = c</code> equations * <code>a<sup>-1</sup> * c = b</code> and <code>c * b<sup>-1</sup> = a</code> are true. * * @return A new complex, which is the inverse of this one */ @Override public Complexd invert() { final double lengthSquared = lengthSquared(); if (Math.abs(lengthSquared) < GenericMath.DBL_EPSILON) { throw new ArithmeticException("Cannot invert a complex of length zero"); } return conjugate().div(lengthSquared); }
/** * Creates a new complex from the float angle in radians. * * @param angle The angle in radians * @return The complex defined by the angle */ public static Complexd fromAngleRad(float angle) { return fromAngleRad((double) angle); }
/** * Normalizes this complex. * * @return A new complex of unit length */ @Override public Complexd normalize() { final double length = length(); if (Math.abs(length) < GenericMath.DBL_EPSILON) { throw new ArithmeticException("Cannot normalize the zero complex"); } return new Complexd(x / length, y / length); }
/** * Divides this complex by another one. * * @param c The complex to divide with * @return The quotient of the two complexes */ public Complexd div(Complexd c) { return div(c.x, c.y); }
/** * Adds the float components of another complex to this one. * * @param x The x (real) component of the complex to add * @param y The y (imaginary) component of the complex to add * @return A new complex, which is the sum of both */ public Complexd add(float x, float y) { return add((double) x, (double) y); }
/** * Returns the angle in degrees formed by the direction vector of this complex on the complex plane. * * @return The angle in degrees of the direction vector of this complex */ public double getAngleDeg() { return (double) Math.toDegrees(getAngleRad()); }
/** * Returns the dot product of this complex with another one. * * @param c The complex to calculate the dot product with * @return The dot product of the two complexes */ public double dot(Complexd c) { return dot(c.x, c.y); }
/** * Multiplies the components of this complex by a double scalar. * * @param a The multiplication scalar * @return A new complex, which has each component multiplied by the scalar */ @Override public Complexd mul(double a) { return new Complexd(x * a, y * a); }
/** * Returns the inverse of this complex. <br> Inversion of a complex <code>a</code> returns complex <code>a<sup>-1</sup> = a' / |a|<sup>2</sup></code> where <code>a'</code> is {@link #conjugate() * conjugation} of <code>a</code>, and <code>|a|<sup>2</sup></code> is squared length of <code>a</code>. <br> For any complexes <code>a, b, c</code>, such that <code>a * b = c</code> equations * <code>a<sup>-1</sup> * c = b</code> and <code>c * b<sup>-1</sup> = a</code> are true. * * @return A new complex, which is the inverse of this one */ @Override public Complexd invert() { final double lengthSquared = lengthSquared(); if (Math.abs(lengthSquared) < GenericMath.DBL_EPSILON) { throw new ArithmeticException("Cannot invert a complex of length zero"); } return conjugate().div(lengthSquared); }
/** * Creates a new complex from the float angle in radians. * * @param angle The angle in radians * @return The complex defined by the angle */ public static Complexd fromAngleRad(float angle) { return fromAngleRad((double) angle); }
/** * Normalizes this complex. * * @return A new complex of unit length */ @Override public Complexd normalize() { final double length = length(); if (Math.abs(length) < GenericMath.DBL_EPSILON) { throw new ArithmeticException("Cannot normalize the zero complex"); } return new Complexd(x / length, y / length); }
/** * Divides the components of this complex by a float scalar. * * @param a The division scalar * @return A new complex, which has each component divided by the scalar */ public Complexd div(float a) { return div((double) a); }
/** * Adds the float components of another complex to this one. * * @param x The x (real) component of the complex to add * @param y The y (imaginary) component of the complex to add * @return A new complex, which is the sum of both */ public Complexd add(float x, float y) { return add((double) x, (double) y); }
/** * Returns the angle in degrees formed by the direction vector of this complex on the complex plane. * * @return The angle in degrees of the direction vector of this complex */ public double getAngleDeg() { return (double) Math.toDegrees(getAngleRad()); }
/** * Returns the dot product of this complex with the float components of another one. * * @param x The x (real) component of the complex to calculate the dot product with * @param y The y (imaginary) component of the complex to calculate the dot product with * @return The dot product of the two complexes */ public double dot(float x, float y) { return dot((double) x, (double) y); }