java.lang.Object
imagingbook.common.math.Complex
This class represents complex numbers. All instances are immutable. Methods are mostly defined to be compatible with org.apache.commons.math3.complex.Complex and (newer) org.apache.commons.numbers.complex.Complex. Arithmetic operations are generally more precise than with the Apache implementation. See also Appendix Sec. A.5 of [1].
[1] W. Burger, M.J. Burge, Digital Image Processing – An Algorithmic Introduction, 3rd ed, Springer (2022).
- Version:
- 2022/07/05
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Complex
Constant - imaginary unit value (z = 0 + i 1).final double
The imaginary part of this complex number (publicly accessible but read-only).static final Complex
Constant - real unit value (z = 1 + i 0).final double
The real part of this complex number (publicly accessible but read-only).static final Complex
Constant - complex zero value (z = 0 + i 0). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondouble
abs()
Returns the absolute value of this complex number, i.e., its radius or distance from the origin.double
abs2()
Returns the squared absolute value of this complex number, i.e., its squared radius or distance from the origin.Adds a complex quantity to this complex number and returns a new complex number.double
arg()
Returns the 'argument' of this complex number, i.e., its angle w.r.t.Returns the conjugatez*
of this complex number, i.e, ifz = a + i b
thenz* = a - i b
.boolean
equals
(double re, double im) Checks if the given complex quantity is equal to thisComplex
quantity, using the default tolerance (Arithmetic.EPSILON_DOUBLE
).boolean
equals
(double re, double im, double tolerance) Checks if the given complex quantity is equal to thisComplex
quantity, using the specified tolerance.boolean
boolean
double
getIm()
Returns the imaginary part of this complex number.double
getRe()
Returns the real part of this complex number.boolean
isNaN()
Returns true if the real or imaginary component of this complex number isNaN
.multiply
(double s) Multiplies this complex number with the scalar factors
and returns a new complex number.Multiplies this complex number with another complex quantity and returns a new complex number.pow
(int k) Returns of value of this complex number (z
) raised to the powerk
(integer).rotate
(double phi) Rotates this complex number by anglephi
and returns the resulting complex number.double[]
toArray()
Returns a 2-element array with the real and imaginary part of this complex number.toString()
-
Field Details
-
ONE
Constant - real unit value (z = 1 + i 0). -
ZERO
Constant - complex zero value (z = 0 + i 0). -
I
Constant - imaginary unit value (z = 0 + i 1). -
re
The real part of this complex number (publicly accessible but read-only). -
im
The imaginary part of this complex number (publicly accessible but read-only).
-
-
Constructor Details
-
Complex
Constructor.- Parameters:
re
- real partim
- imaginary part
-
Complex
Constructor.- Parameters:
z
- a two-elementdouble
array with real and imaginary part
-
Complex
Constructor.- Parameters:
z
- complex quantity, which is duplicated
-
Complex
Constructor, creates a complex quantity on the unit circle with anglephi
:e^(i * phi) = cos(phi) + i * sin(phi)
.- Parameters:
phi
- the angle- See Also:
-
-
Method Details
-
abs
Returns the absolute value of this complex number, i.e., its radius or distance from the origin.- Returns:
- the absolute value
-
abs2
Returns the squared absolute value of this complex number, i.e., its squared radius or distance from the origin.- Returns:
- the squared absolute value
-
arg
Returns the 'argument' of this complex number, i.e., its angle w.r.t. to the real axis.- Returns:
- the argument (in radians)
-
conjugate
Returns the conjugatez*
of this complex number, i.e, ifz = a + i b
thenz* = a - i b
.- Returns:
- the complex conjugate
-
add
Adds a complex quantity to this complex number and returns a new complex number.- Parameters:
z
- complex value- Returns:
- the sum of this complex number and
z
-
rotate
Rotates this complex number by anglephi
and returns the resulting complex number.- Parameters:
phi
- the angle (in radians)- Returns:
- the rotated complex value
-
toString
-
isNaN
Returns true if the real or imaginary component of this complex number isNaN
.- Returns:
- true if
NaN
, otherwise false
-
getRe
Returns the real part of this complex number.- Returns:
- the real part
-
getIm
Returns the imaginary part of this complex number.- Returns:
- the imaginary part
-
multiply
Multiplies this complex number with another complex quantity and returns a new complex number.- Parameters:
z
- a complex quantity- Returns:
- this complex number multiplied by
z
-
multiply
Multiplies this complex number with the scalar factors
and returns a new complex number.- Parameters:
s
- a scalar factor- Returns:
- this complex number multiplied by
s
-
pow
Returns of value of this complex number (z
) raised to the powerk
(integer).- Parameters:
k
- the integer exponent (≥ 0)- Returns:
z^k
-
toArray
Returns a 2-element array with the real and imaginary part of this complex number.- Returns:
- (re, im)
-
equals
Checks if the givenObject
is equal to thisComplex
quantity. Callsequals(Complex, double)
if the argument is of typeComplex
, otherwisenull
is returned. -
equals
- Parameters:
z
- anotherComplex
quantitytolerance
- the maximum difference of real and imaginary parts- Returns:
- true if the two complex quantities are sufficiently close, false otherwise
-
equals
Checks if the given complex quantity is equal to thisComplex
quantity, using the default tolerance (Arithmetic.EPSILON_DOUBLE
).- Parameters:
re
- real part of other complex quantityim
- imaginary part of other complex quantity- Returns:
- true if the two complex quantities are sufficiently close, false otherwise
-
equals
Checks if the given complex quantity is equal to thisComplex
quantity, using the specified tolerance.- Parameters:
re
- real part of other complex quantityim
- imaginary part of other complex quantitytolerance
- the maximum difference of real and imaginary parts- Returns:
- true if the two complex quantities are sufficiently close, false otherwise
-