- java.lang.Object
-
- org.spongepowered.math.imaginary.Complexd
-
- All Implemented Interfaces:
Serializable,Comparable<Complexd>,Imaginaryd
@Immutable public final class Complexd extends Object implements Imaginaryd, Comparable<Complexd>, Serializable
Represent a complex number of the formx + yi. The x and y components are stored asdoubles. This class is immutable.- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Complexdadd(double x, double y)Adds the double components of another complex to this one.Complexdadd(float x, float y)Adds the float components of another complex to this one.Complexdadd(Complexd c)Adds another complex to this one.doubleangleDeg()Returns the angle in degrees formed by the direction vector of this complex on the complex plane.doubleangleRad()Returns the angle in radians formed by the direction vector of this complex on the complex plane.intcompareTo(Complexd that)Complexdconjugate()Returns the conjugate of this complex.Vector2ddirection()Returns a unit vector pointing in the same direction as this complex on the complex plane.Complexddiv(double a)Divides the components of this complex by a double scalar.Complexddiv(double x, double y)Divides this complex by the double components of another one.Complexddiv(float a)Divides the components of this complex by a float scalar.Complexddiv(float x, float y)Divides this complex by the float components of another one.Complexddiv(Complexd c)Divides this complex by another one.doubledot(double x, double y)Returns the dot product of this complex with the double components of another one.doubledot(float x, float y)Returns the dot product of this complex with the float components of another one.doubledot(Complexd c)Returns the dot product of this complex with another one.booleanequals(Object other)static Complexdfrom(double x, double y)Creates a new complex from the double components.static ComplexdfromAngleDeg(double angle)Creates a new complex from the double angle in radians.static ComplexdfromAngleDeg(float angle)Creates a new complex from the float angle in degrees.static ComplexdfromAngleRad(double angle)Creates a new complex from the double angle in radians.static ComplexdfromAngleRad(float angle)Creates a new complex from the float angle in radians.static ComplexdfromImaginary(double y)Creates a new complex from the double imaginary components.static ComplexdfromReal(double x)Creates a new complex from the double real component.static ComplexdfromRotationTo(Vector2d from, Vector2d to)Creates a new complex from the angle defined from the first to the second vector.static ComplexdfromRotationTo(Vector3d from, Vector3d to)Creates a new complex from the angle defined from the first to the second vector.inthashCode()Complexdinvert()Returns the inverse of this complex.doublelength()Returns the length of this complex.doublelengthSquared()Returns the square of the length of this complex.Complexdmul(double a)Multiplies the components of this complex by a double scalar.Complexdmul(double x, double y)Multiplies the double components of another complex with this one.Complexdmul(float a)Multiplies the components of this complex by a float scalar.Complexdmul(float x, float y)Multiplies the float components of another complex with this one.Complexdmul(Complexd c)Multiplies another complex with this one.Complexdnormalize()Normalizes this complex.Vector2drotate(double x, double y)Rotates the double components of a vector by this complex.Vector2drotate(float x, float y)Rotates the float components of a vector by this complex.Vector2drotate(Vector2d v)Rotates a vector by this complex.Complexdsub(double x, double y)Subtracts the double components of another complex from this one.Complexdsub(float x, float y)Subtracts the float components of another complex from this one.Complexdsub(Complexd c)Subtracts another complex from this one.ComplexdtoDouble()ComplexftoFloat()QuaterniondtoQuaternion()Converts this complex to a quaternion by using (0, 0, 1) as a rotation axis.QuaterniondtoQuaternion(double x, double y, double z)Converts this complex to a quaternion by using the provided double components vector as a rotation axis.QuaterniondtoQuaternion(float x, float y, float z)Converts this complex to a quaternion by using the provided float components vector as a rotation axis.QuaterniondtoQuaternion(Vector3d axis)Converts this complex to a quaternion by using the provided vector as a rotation axis.StringtoString()doublex()Gets the x (real) component of this complex.doubley()Gets the y (imaginary) component of this complex.
-
-
-
Constructor Detail
-
Complexd
public Complexd(float x, float y)Constructs a new complex from the float components.- Parameters:
x- The x (real) componenty- The y (imaginary) component
-
Complexd
public Complexd(double x, double y)Constructs a new complex from the double components.- Parameters:
x- The x (real) componenty- The y (imaginary) component
-
-
Method Detail
-
x
public double x()
Gets the x (real) component of this complex.- Returns:
- The x (real) component
-
y
public double y()
Gets the y (imaginary) component of this complex.- Returns:
- The y (imaginary) component
-
add
public Complexd add(Complexd c)
Adds another complex to this one.- Parameters:
c- The complex to add- Returns:
- A new complex, which is the sum of both
-
add
public Complexd add(float x, float y)
Adds the float components of another complex to this one.- Parameters:
x- The x (real) component of the complex to addy- The y (imaginary) component of the complex to add- Returns:
- A new complex, which is the sum of both
-
add
public Complexd add(double x, double y)
Adds the double components of another complex to this one.- Parameters:
x- The x (real) component of the complex to addy- The y (imaginary) component of the complex to add- Returns:
- A new complex, which is the sum of both
-
sub
public Complexd sub(Complexd c)
Subtracts another complex from this one.- Parameters:
c- The complex to subtract- Returns:
- A new complex, which is the difference of both
-
sub
public Complexd sub(float x, float y)
Subtracts the float components of another complex from this one.- Parameters:
x- The x (real) component of the complex to subtracty- The y (imaginary) component of the complex to subtract- Returns:
- A new complex, which is the difference of both
-
sub
public Complexd sub(double x, double y)
Subtracts the double components of another complex from this one.- Parameters:
x- The x (real) component of the complex to subtracty- The y (imaginary) component of the complex to subtract- Returns:
- A new complex, which is the difference of both
-
mul
public Complexd mul(float a)
Multiplies the components of this complex by a float scalar.- Parameters:
a- The multiplication scalar- Returns:
- A new complex, which has each component multiplied by the scalar
-
mul
public Complexd mul(double a)
Multiplies the components of this complex by a double scalar.- Specified by:
mulin interfaceImaginaryd- Parameters:
a- The multiplication scalar- Returns:
- A new complex, which has each component multiplied by the scalar
-
mul
public Complexd mul(Complexd c)
Multiplies another complex with this one.- Parameters:
c- The complex to multiply with- Returns:
- A new complex, which is the product of both
-
mul
public Complexd mul(float x, float y)
Multiplies the float components of another complex with this one.- Parameters:
x- The x (real) component of the complex to multiply withy- The y (imaginary) component of the complex to multiply with- Returns:
- A new complex, which is the product of both
-
mul
public Complexd mul(double x, double y)
Multiplies the double components of another complex with this one.- Parameters:
x- The x (real) component of the complex to multiply withy- The y (imaginary) component of the complex to multiply with- Returns:
- A new complex, which is the product of both
-
div
public Complexd div(float a)
Divides the components of this complex by a float scalar.- Parameters:
a- The division scalar- Returns:
- A new complex, which has each component divided by the scalar
-
div
public Complexd div(double a)
Divides the components of this complex by a double scalar.- Specified by:
divin interfaceImaginaryd- Parameters:
a- The division scalar- Returns:
- A new complex, which has each component divided by the scalar
-
div
public Complexd div(Complexd c)
Divides this complex by another one.- Parameters:
c- The complex to divide with- Returns:
- The quotient of the two complexes
-
div
public Complexd div(float x, float y)
Divides this complex by the float components of another one.- Parameters:
x- The x (real) component of the complex to divide withy- The y (imaginary) component of the complex to divide with- Returns:
- The quotient of the two complexes
-
div
public Complexd div(double x, double y)
Divides this complex by the double components of another one.- Parameters:
x- The x (real) component of the complex to divide withy- The y (imaginary) component of the complex to divide with- Returns:
- The quotient of the two complexes
-
dot
public double dot(Complexd c)
Returns the dot product of this complex with another one.- Parameters:
c- The complex to calculate the dot product with- Returns:
- The dot product of the two complexes
-
dot
public double dot(float x, float y)Returns the dot product of this complex with the float components of another one.- Parameters:
x- The x (real) component of the complex to calculate the dot product withy- The y (imaginary) component of the complex to calculate the dot product with- Returns:
- The dot product of the two complexes
-
dot
public double dot(double x, double y)Returns the dot product of this complex with the double components of another one.- Parameters:
x- The x (real) component of the complex to calculate the dot product withy- The y (imaginary) component of the complex to calculate the dot product with- Returns:
- The dot product of the two complexes
-
rotate
public Vector2d rotate(Vector2d v)
Rotates a vector by this complex.- Parameters:
v- The vector to rotate- Returns:
- The rotated vector
-
rotate
public Vector2d rotate(float x, float y)
Rotates the float components of a vector by this complex.- Parameters:
x- The x component of the vectory- The y component of the vector- Returns:
- The rotated vector
-
rotate
public Vector2d rotate(double x, double y)
Rotates the double components of a vector by this complex.- Parameters:
x- The x component of the vectory- The y component of the vector- Returns:
- The rotated vector
-
direction
public Vector2d direction()
Returns a unit vector pointing in the same direction as this complex on the complex plane.- Returns:
- The vector representing the direction this complex is pointing to
-
angleRad
public double angleRad()
Returns the angle in radians formed by the direction vector of this complex on the complex plane.- Returns:
- The angle in radians of the direction vector of this complex
-
angleDeg
public double angleDeg()
Returns the angle in degrees formed by the direction vector of this complex on the complex plane.- Returns:
- The angle in degrees of the direction vector of this complex
-
conjugate
public Complexd conjugate()
Returns the conjugate of this complex.
Conjugation of a complexais an operation returning complexa'such thata' * a = a * a' = |a|2where|a|2is squared length ofa.- Specified by:
conjugatein interfaceImaginaryd- Returns:
- A new complex, which is the conjugate of this one
-
invert
public Complexd invert()
Returns the inverse of this complex.
Inversion of a complexareturns complexa-1 = a' / |a|2wherea'isconjugationofa, and|a|2is squared length ofa.
For any complexesa, b, c, such thata * b = cequationsa-1 * c = bandc * b-1 = aare true.- Specified by:
invertin interfaceImaginaryd- Returns:
- A new complex, which is the inverse of this one
-
lengthSquared
public double lengthSquared()
Returns the square of the length of this complex.- Specified by:
lengthSquaredin interfaceImaginaryd- Returns:
- The square of the length
-
length
public double length()
Returns the length of this complex.- Specified by:
lengthin interfaceImaginaryd- Returns:
- The length
-
normalize
public Complexd normalize()
Normalizes this complex.- Specified by:
normalizein interfaceImaginaryd- Returns:
- A new complex of unit length
-
toQuaternion
public Quaterniond toQuaternion()
Converts this complex to a quaternion by using (0, 0, 1) as a rotation axis.- Returns:
- A quaternion of this rotation around the unit z
-
toQuaternion
public Quaterniond toQuaternion(Vector3d axis)
Converts this complex to a quaternion by using the provided vector as a rotation axis.- Parameters:
axis- The rotation axis- Returns:
- A quaternion of this rotation around the given axis
-
toQuaternion
public Quaterniond toQuaternion(float x, float y, float z)
Converts this complex to a quaternion by using the provided float components vector as a rotation axis.- Parameters:
x- The x component of the axis vectory- The y component of the axis vectorz- The z component of the axis vector- Returns:
- A quaternion of this rotation around the given axis
-
toQuaternion
public Quaterniond toQuaternion(double x, double y, double z)
Converts this complex to a quaternion by using the provided double components vector as a rotation axis.- Parameters:
x- The x component of the axis vectory- The y component of the axis vectorz- The z component of the axis vector- Returns:
- A quaternion of this rotation around the given axis
-
toFloat
public Complexf toFloat()
- Specified by:
toFloatin interfaceImaginaryd
-
toDouble
public Complexd toDouble()
- Specified by:
toDoublein interfaceImaginaryd
-
compareTo
public int compareTo(Complexd that)
- Specified by:
compareToin interfaceComparable<Complexd>
-
fromReal
public static Complexd fromReal(double x)
Creates a new complex from the double real component.The
ZEROconstant is re-used whenxis 0.- Parameters:
x- The x (real) component- Returns:
- The complex created from the double real component
-
fromImaginary
public static Complexd fromImaginary(double y)
Creates a new complex from the double imaginary components.The
ZEROconstant is re-used whenyis 0.- Parameters:
y- The y (imaginary) component- Returns:
- The complex created from the double imaginary component
-
from
public static Complexd from(double x, double y)
Creates a new complex from the double components.The
ZEROconstant is re-used when bothxandzare 0.- Parameters:
x- The x (real) componenty- The y (imaginary) component- Returns:
- The complex created from the double components
-
fromRotationTo
public static Complexd fromRotationTo(Vector2d from, Vector2d to)
Creates a new complex from the angle defined from the first to the second vector.- Parameters:
from- The first vectorto- The second vector- Returns:
- The complex defined by the angle between the vectors
-
fromRotationTo
public static Complexd fromRotationTo(Vector3d from, Vector3d to)
Creates a new complex from the angle defined from the first to the second vector.- Parameters:
from- The first vectorto- The second vector- Returns:
- The complex defined by the angle between the vectors
-
fromAngleDeg
public static Complexd fromAngleDeg(float angle)
Creates a new complex from the float angle in degrees.- Parameters:
angle- The angle in degrees- Returns:
- The complex defined by the angle
-
fromAngleRad
public static Complexd fromAngleRad(float angle)
Creates a new complex from the float angle in radians.- Parameters:
angle- The angle in radians- Returns:
- The complex defined by the angle
-
fromAngleDeg
public static Complexd fromAngleDeg(double angle)
Creates a new complex from the double angle in radians.- Parameters:
angle- The angle in radians- Returns:
- The complex defined by the angle
-
fromAngleRad
public static Complexd fromAngleRad(double angle)
Creates a new complex from the double angle in radians.- Parameters:
angle- The angle in radians- Returns:
- The complex defined by the angle
-
-