Package mandelbrot
Class Complex
java.lang.Object
mandelbrot.Complex
The
Complex class represents a complex number.
Complex numbers are immutable: their values cannot be changed after they
are created.
It includes methods for addition, subtraction, multiplication, division,
conjugation, and other common functions on complex numbers.-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionComplex(double real, double imaginary)Initializes a complex number with the specified real and imaginary parts. -
Method Summary
Modifier and TypeMethodDescriptionReturns aComplexwhose value is(this + addend).Returns the conjugate of this complex number.Returns aComplexwhose value isthis / divisor.booleanTest for equality with another object.doubleReturns the imaginary part of this complex number.doublegetReal()Returns the real part of this complex number.doublemodulus()Returns the modulus (distance to zero) of this complex number.Returns aComplexwhose value isthis * factornegate()Returns the negation of this complex number.pow(int p)Returns the integral power of this complex number.static Complexreal(double real)Creates a complex number with the specified real part and an imaginary part equal to zero.Returns the reciprocal of this complex number.static Complexrotation(double radians)Returns a complex number, whose multiplication corresponds to a rotation by the given angle in the complex plane.scale(double lambda)Returns the scalar multiplication of this complex number.doubleReturns the squared modulus of this complex number.Returns aComplexwhose value is(this - subtrahend).toString()Returns a string representation of this complex number.
-
Field Details
-
ZERO
Zero as a complex number, i.e., a number representing "0.0 + 0.0i". -
ONE
One seen as a complex number, i.e., a number representing "1.0 + 0.0i". -
I
The square root of -1, i.e., a number representing "0.0 + 1.0i".
-
-
Constructor Details
-
Complex
public Complex(double real, double imaginary)Initializes a complex number with the specified real and imaginary parts.- Parameters:
real- the real partimaginary- the imaginary part
-
-
Method Details
-
getReal
public double getReal()Returns the real part of this complex number.- Returns:
- the real part of this complex number
-
getImaginary
public double getImaginary()Returns the imaginary part of this complex number.- Returns:
- the imaginary part of this complex number
-
rotation
Returns a complex number, whose multiplication corresponds to a rotation by the given angle in the complex plane. This corresponds to the complex with absolute value equal to one and an argument equal to the specifiedangle.- Parameters:
radians- the angle of the rotation (counterclockwise) in radians- Returns:
- a complex number, whose multiplication corresponds to a rotation by the given angle.
-
real
Creates a complex number with the specified real part and an imaginary part equal to zero.- Parameters:
real- the real component- Returns:
- the complex
real + 0i
-
add
Returns aComplexwhose value is(this + addend).- Parameters:
addend- a complex- Returns:
- the complex number whose value is
this + addend
-
negate
Returns the negation of this complex number.- Returns:
- A complex
csuch thatthis + c = 0
-
conjugate
Returns the conjugate of this complex number.- Returns:
- A complex
csuch thatthis * c = ||this|| ** 2
-
subtract
Returns aComplexwhose value is(this - subtrahend).- Parameters:
subtrahend- the complex to be subtracted fromthis- Returns:
- the complex number
(this - subtrahend)
-
multiply
Returns aComplexwhose value isthis * factor- Parameters:
factor- the complex number to multiply tothis- Returns:
- the complex number
this * factor
-
squaredModulus
public double squaredModulus()Returns the squared modulus of this complex number.- Returns:
||this|| ** 2
-
modulus
public double modulus()Returns the modulus (distance to zero) of this complex number.- Returns:
||this||
-
reciprocal
Returns the reciprocal of this complex number.- Returns:
- a complex number
csuch thatthis * c = 1
-
divide
Returns aComplexwhose value isthis / divisor.- Parameters:
divisor- the denominator (a complex number)- Returns:
- the complex number
this / divisor
-
pow
Returns the integral power of this complex number.- Parameters:
p- a non-negative integer- Returns:
- the complex number
this ** p
-
scale
Returns the scalar multiplication of this complex number.- Parameters:
lambda- a scalar number- Returns:
- the complex number
lambda * this
-
equals
Test for equality with another object. If both the real and imaginary parts of two complex numbers are considered equal according toHelpers.doubleCompare(i.e., withinHelpers.RANGE), the two Complex objects are considered to be equal. -
toString
Returns a string representation of this complex number.
-