/** * Subtracts the float components of another complex from this one. * * @param x The x (real) component of the complex to subtract * @param y The y (imaginary) component of the complex to subtract * @return A new complex, which is the difference of both */ public Complexf sub(float x, float y) { return new Complexf(this.x - x, this.y - y); }
/** * Adds another complex to this one. * * @param c The complex to add * @return A new complex, which is the sum of both */ public Complexf add(Complexf c) { return add(c.x, c.y); }
/** * Divides this complex by another one. * * @param c The complex to divide with * @return The quotient of the two complexes */ public Complexf div(Complexf c) { return div(c.x, c.y); }
/** * 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 Complexf invert() { final float lengthSquared = lengthSquared(); if (Math.abs(lengthSquared) < GenericMath.FLT_EPSILON) { throw new ArithmeticException("Cannot invert a complex of length zero"); } return conjugate().div(lengthSquared); }
/** * Creates a new complex from the double angle in radians. * * @param angle The angle in radians * @return The complex defined by the angle */ public static Complexf fromAngleRad(double angle) { return fromAngleRad((float) angle); }
/** * Normalizes this complex. * * @return A new complex of unit length */ @Override public Complexf normalize() { final float length = length(); if (Math.abs(length) < GenericMath.FLT_EPSILON) { throw new ArithmeticException("Cannot normalize the zero complex"); } return new Complexf(x / length, y / length); }
/** * 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 float getAngleDeg() { return (float) 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 float dot(Complexf c) { return dot(c.x, c.y); }
/** * Rotates the float components of a vector by this complex. * * @param x The x component of the vector * @param y The y component of the vector * @return The rotated vector */ public Vector2f rotate(float x, float y) { final float length = length(); if (Math.abs(length) < GenericMath.FLT_EPSILON) { throw new ArithmeticException("Cannot rotate by the zero complex"); } final float nx = this.x / length; final float ny = this.y / length; return new Vector2f(x * nx - y * ny, y * nx + x * ny); }
/** * 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 Complexf invert() { final float lengthSquared = lengthSquared(); if (Math.abs(lengthSquared) < GenericMath.FLT_EPSILON) { throw new ArithmeticException("Cannot invert a complex of length zero"); } return conjugate().div(lengthSquared); }
/** * Creates a new complex from the double angle in radians. * * @param angle The angle in radians * @return The complex defined by the angle */ public static Complexf fromAngleRad(double angle) { return fromAngleRad((float) angle); }
/** * Normalizes this complex. * * @return A new complex of unit length */ @Override public Complexf normalize() { final float length = length(); if (Math.abs(length) < GenericMath.FLT_EPSILON) { throw new ArithmeticException("Cannot normalize the zero complex"); } return new Complexf(x / length, y / length); }
/** * 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 float getAngleDeg() { return (float) 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 float dot(Complexf c) { return dot(c.x, c.y); }
/** * Rotates the float components of a vector by this complex. * * @param x The x component of the vector * @param y The y component of the vector * @return The rotated vector */ public Vector2f rotate(float x, float y) { final float length = length(); if (Math.abs(length) < GenericMath.FLT_EPSILON) { throw new ArithmeticException("Cannot rotate by the zero complex"); } final float nx = this.x / length; final float ny = this.y / length; return new Vector2f(x * nx - y * ny, y * nx + x * ny); }
/** * Multiplies the float 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 Complexf mul(float x, float y) { return new Complexf( this.x * x - this.y * y, this.x * y + this.y * x); }
/** * Creates a new complex from the double angle in degrees. * * @param angle The angle in degrees * @return The complex defined by the angle */ public static Complexf fromAngleDeg(double angle) { return fromAngleRad(Math.toRadians(angle)); }