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 double
abs()
Returns the absolute value [ = | c | ].double
abs2()
Returns the squared absolute value [ = | c |^2 ].Complex
add(Complex b)
Adds a complex number [ c = c + b ].static Complex
add(Complex a, Complex b)
Sums two complex numbers [ = a + b ].double
arg()
Returns the argument [ = <(c) ].Complex
conj()
Builds the conjugate [ c = c ].static Complex
conj(Complex c)
Creates the conjugate [ = c ].Complex
div(double r)
Divides by a real number [ c = c / r ].Complex
div(Complex b)
Divides by a complex number [ c = c / b ].static double
dot(Complex a, Complex b)
Returns the dot product between two complex numbers.boolean
equals(double x, double y)
Compares with a complex number [ c = (x,y) ?boolean
equals(java.lang.Object c)
Compares with a complex number [ c = c ?static Complex
exp(Complex a)
Returns the value of the complex exponential function [ = exp a ].static Complex
expi(double y)
Returns the value of the complex exponential function [ = exp iy ].int
hashCode()
Returns the hash code [ =####
].Complex
inv()
Builds the inverse number [ c = 1 / c ].static Complex
inv(Complex c)
Creates the inverse number [ = 1 / c ].Complex
mul(double r)
Multiplies by a real number [ c = c r ].Complex
mul(Complex b)
Multiplies by a complex number [ c = c b ].static Complex
mul(Complex c, double r)
Multiplies a complex number by a real number.static Complex
mul(Complex a, Complex b)
Multiplies two complex numbers.Complex
neg()
Builds the negated number [ c = -c ].static Complex
neg(Complex c)
Creates the negated number [ = -c ].Complex
norm()
Normalizes the absolute value to 1 [ c = c / | c | ].static Complex
norm(Complex c)
Creates the normalization of the complex number to 1.Complex
sub(Complex b)
Substracts a complex number [ c = c - b ].static Complex
sub(Complex a, Complex b)
Substracts two complex numbers [ = a - b ].java.lang.String
toString()
String representation [ = "..." ].static Complex
vec(double a_z, Complex b)
Returns the three dimensional vector product between two vectors [ = a x b ].static double
vec(Complex a, Complex b)
Returns the three dimensional vector product between two vectors [ = a x b ].boolean
zero()
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:
hashCode
in classjava.lang.Object
- Returns:
- the hash code
-
toString
public java.lang.String toString()String representation [ = "..." ].- Overrides:
toString
in classjava.lang.Object
- Returns:
- the string
-
equals
public boolean equals(java.lang.Object c)Compares with a complex number [ c = c ? ].- Overrides:
equals
in 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
-