Package hoverball.math
Class Complex
java.lang.Object
hoverball.math.Complex
public final class Complex
extends java.lang.Object
The class Complex represents a complex number of the two dimensional
complex plane.
Let be:
a, b, c - complex numbers
x, y, z - real numbers (as coordinates)
r - real number
v - vector
c - the complex number of the Complex object itself
Operator Overloading for Groovy, Scala, Kotlin and Jython is supported.
-
Field Summary
-
Constructor Summary
Constructors Constructor Description Complex()Creates a complex number with the coordinates (0,0).Complex(double x)Creates a complex number with the coordinates (x,0).Complex(double x, double y)Creates a complex number with the coordinates (x,y).Complex(Complex c)Creates a complex number equal to another.Complex(Vector v)Creates a complex number from a vector. -
Method Summary
Modifier and Type Method Description doubleabs()Returns the absolute value [ = | c | ].doubleabs2()Returns the squared absolute value [ = | c |^2 ].Complexadd(Complex b)Adds a complex number [ c = c + b ].static Complexadd(Complex a, Complex b)Sums two complex numbers [ = a + b ].doublearg()Returns the argument [ = <(c) ].Complexconj()Builds the conjugate [ c = c ].static Complexconj(Complex c)Creates the conjugate [ = c ].Complexdiv(double r)Divides by a real number [ c = c / r ].Complexdiv(Complex b)Divides by a complex number [ c = c / b ].static doubledot(Complex a, Complex b)Returns the dot product between two complex numbers.booleanequals(double x, double y)Compares with a complex number [ c = (x,y) ?booleanequals(java.lang.Object c)Compares with a complex number [ c = c ?static Complexexp(Complex a)Returns the value of the complex exponential function [ = exp a ].static Complexexpi(double y)Returns the value of the complex exponential function [ = exp iy ].inthashCode()Returns the hash code [ =####].Complexinv()Builds the inverse number [ c = 1 / c ].static Complexinv(Complex c)Creates the inverse number [ = 1 / c ].Complexmul(double r)Multiplies by a real number [ c = c r ].Complexmul(Complex b)Multiplies by a complex number [ c = c b ].static Complexmul(Complex c, double r)Multiplies a complex number by a real number.static Complexmul(Complex a, Complex b)Multiplies two complex numbers.Complexneg()Builds the negated number [ c = -c ].static Complexneg(Complex c)Creates the negated number [ = -c ].Complexnorm()Normalizes the absolute value to 1 [ c = c / | c | ].static Complexnorm(Complex c)Creates the normalization of the complex number to 1.Complexsub(Complex b)Substracts a complex number [ c = c - b ].static Complexsub(Complex a, Complex b)Substracts two complex numbers [ = a - b ].java.lang.StringtoString()String representation [ = "..." ].static Complexvec(double a_z, Complex b)Returns the three dimensional vector product between two vectors [ = a x b ].static doublevec(Complex a, Complex b)Returns the three dimensional vector product between two vectors [ = a x b ].booleanzero()Tests if zero [ c = 0 ?
-
Field Details
-
format
public static java.text.DecimalFormat formatDecimalFormat object for string conversion.This object is used for formatting all objects of this package. The default format is
0.###withLocale.US. -
x
public final double xx-coordinate of the complex number. -
y
public final double yy-coordinate of the complex number.
-
-
Constructor Details
-
Complex
public Complex()Creates a complex number with the coordinates (0,0). -
Complex
public Complex(double x, double y)Creates a complex number with the coordinates (x,y).- Parameters:
x- x-coordinatey- y-coordinate
-
Complex
public Complex(double x)Creates a complex number with the coordinates (x,0).- Parameters:
x- x-coordinate
-
Complex
Creates a complex number equal to another.- Parameters:
c- copied complex number
-
Complex
Creates a complex number from a vector.The z-coordinate of the vector is ignored.
- Parameters:
v- vector
-
-
Method Details
-
hashCode
public int hashCode()Returns the hash code [ =####].- Overrides:
hashCodein classjava.lang.Object- Returns:
- the hash code
-
toString
public java.lang.String toString()String representation [ = "..." ].- Overrides:
toStringin classjava.lang.Object- Returns:
- the string
-
equals
public boolean equals(java.lang.Object c)Compares with a complex number [ c = c ? ].- Overrides:
equalsin classjava.lang.Object- Parameters:
c- complex number- Returns:
- the equality
-
equals
public boolean equals(double x, double y)Compares with a complex number [ c = (x,y) ? ].- Parameters:
x- real numbery- real number- Returns:
- the equality
-
add
Adds a complex number [ c = c + b ].- Parameters:
b- complex number- Returns:
- this
-
sub
Substracts a complex number [ c = c - b ].- Parameters:
b- complex number- Returns:
- this
-
mul
Multiplies by a real number [ c = c r ].- Parameters:
r- real number- Returns:
- this
-
mul
Multiplies by a complex number [ c = c b ].- Parameters:
b- complex number- Returns:
- this
-
div
Divides by a real number [ c = c / r ].- Parameters:
r- real number- Returns:
- this
-
div
Divides by a complex number [ c = c / b ].- Parameters:
b- complex number- Returns:
- this
-
inv
Builds the inverse number [ c = 1 / c ].- Returns:
- this
-
neg
Builds the negated number [ c = -c ].- Returns:
- this
-
conj
Builds the conjugate [ c = c ].- Returns:
- this
-
zero
public final boolean zero()Tests if zero [ c = 0 ? ].- Returns:
- true, if this complex number equals (0,0)
-
arg
public final double arg()Returns the argument [ = <(c) ]. If the complex number is zero, the function returns the value null.- Returns:
- the argument
-
abs
public final double abs()Returns the absolute value [ = | c | ].- Returns:
- the absolute value
-
abs2
public final double abs2()Returns the squared absolute value [ = | c |^2 ].- Returns:
- the squared absolute value
-
norm
Normalizes the absolute value to 1 [ c = c / | c | ].- Returns:
- this
-
add
Sums two complex numbers [ = a + b ].- Parameters:
a- complex numberb- complex number- Returns:
- the sum
-
sub
Substracts two complex numbers [ = a - b ].- Parameters:
a- complex numberb- complex number- Returns:
- the difference
-
neg
Creates the negated number [ = -c ].- Parameters:
c- complex number- Returns:
- the negated number
-
inv
Creates the inverse number [ = 1 / c ].- Parameters:
c- complex number- Returns:
- die inverse number
-
conj
Creates the conjugate [ = c ].- Parameters:
c- complex number- Returns:
- the conjugate
-
norm
Creates the normalization of the complex number to 1. [ = c / | c | ].- Parameters:
c- complex number- Returns:
- the normalization
-
mul
Multiplies a complex number by a real number. [ = c r ].- Parameters:
c- complex numberr- real number- Returns:
- the product
-
mul
Multiplies two complex numbers. [ = a b ].- Parameters:
a- complex numberb- complex number- Returns:
- the complex product
-
dot
Returns the dot product between two complex numbers. [ = < a, b > ].- Parameters:
a- complex numberb- complex number- Returns:
- the dot product
-
vec
Returns the three dimensional vector product between two vectors [ = a x b ].Formula: (a.x, a.y, 0) x (b.x, b.y, 0) = (0, 0, c.z)
- Parameters:
a- complex numberb- complex number- Returns:
- the z-coordinate of the vector product
-
vec
Returns the three dimensional vector product between two vectors [ = a x b ].Formula: (0, 0, a.z) x (b.x, b.y, 0) = (c.x, c.y, 0)
- Parameters:
a_z- real numberb- complex number- Returns:
- the (x,y)-coordinates of the vector product
-
expi
Returns the value of the complex exponential function [ = exp iy ].- Parameters:
y- real number- Returns:
- the exponential value
-
exp
Returns the value of the complex exponential function [ = exp a ].- Parameters:
a- complex number- Returns:
- the exponential value
-