Package mandelbrot

Class Complex

java.lang.Object
mandelbrot.Complex

public class Complex extends Object
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
    Modifier and Type
    Field
    Description
    static Complex
    The square root of -1, i.e., a number representing "0.0 + 1.0i".
    static Complex
    One seen as a complex number, i.e., a number representing "1.0 + 0.0i".
    static Complex
    Zero as a complex number, i.e., a number representing "0.0 + 0.0i".
  • Constructor Summary

    Constructors
    Constructor
    Description
    Complex​(double real, double imaginary)
    Initializes a complex number with the specified real and imaginary parts.
  • Method Summary

    Modifier and Type
    Method
    Description
    add​(Complex addend)
    Returns a Complex whose value is (this + addend).
    Returns the conjugate of this complex number.
    divide​(Complex divisor)
    Returns a Complex whose value is this / divisor.
    boolean
    equals​(Object other)
    Test for equality with another object.
    double
    Returns the imaginary part of this complex number.
    double
    Returns the real part of this complex number.
    double
    Returns the modulus (distance to zero) of this complex number.
    multiply​(Complex factor)
    Returns a Complex whose value is this * factor
    Returns the negation of this complex number.
    pow​(int p)
    Returns the integral power of this complex number.
    static Complex
    real​(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 Complex
    rotation​(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.
    double
    Returns the squared modulus of this complex number.
    subtract​(Complex subtrahend)
    Returns a Complex whose value is (this - subtrahend).
    Returns a string representation of this complex number.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • ZERO

      public static Complex ZERO
      Zero as a complex number, i.e., a number representing "0.0 + 0.0i".
    • ONE

      public static Complex ONE
      One seen as a complex number, i.e., a number representing "1.0 + 0.0i".
    • I

      public static Complex 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 part
      imaginary - 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

      public static Complex rotation(double radians)
      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 specified angle.
      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

      public static Complex real(double 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

      public Complex add(Complex addend)
      Returns a Complex whose value is (this + addend).
      Parameters:
      addend - a complex
      Returns:
      the complex number whose value is this + addend
    • negate

      public Complex negate()
      Returns the negation of this complex number.
      Returns:
      A complex c such that this + c = 0
    • conjugate

      public Complex conjugate()
      Returns the conjugate of this complex number.
      Returns:
      A complex c such that this * c = ||this|| ** 2
    • subtract

      public Complex subtract(Complex subtrahend)
      Returns a Complex whose value is (this - subtrahend).
      Parameters:
      subtrahend - the complex to be subtracted from this
      Returns:
      the complex number (this - subtrahend)
    • multiply

      public Complex multiply(Complex factor)
      Returns a Complex whose value is this * factor
      Parameters:
      factor - the complex number to multiply to this
      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

      public Complex reciprocal()
      Returns the reciprocal of this complex number.
      Returns:
      a complex number c such that this * c = 1
    • divide

      public Complex divide(Complex divisor)
      Returns a Complex whose value is this / divisor.
      Parameters:
      divisor - the denominator (a complex number)
      Returns:
      the complex number this / divisor
    • pow

      public Complex pow(int p)
      Returns the integral power of this complex number.
      Parameters:
      p - a non-negative integer
      Returns:
      the complex number this ** p
    • scale

      public Complex scale(double lambda)
      Returns the scalar multiplication of this complex number.
      Parameters:
      lambda - a scalar number
      Returns:
      the complex number lambda * this
    • equals

      public boolean equals(Object other)
      Test for equality with another object. If both the real and imaginary parts of two complex numbers are considered equal according to Helpers.doubleCompare (i.e., within Helpers.RANGE), the two Complex objects are considered to be equal.
      Overrides:
      equals in class Object
      Parameters:
      other - Object to test for equality with this instance.
      Returns:
      true if the objects are equal, false if object is null, not an instance of Complex, or not equal to this instance.
    • toString

      public String toString()
      Returns a string representation of this complex number.
      Overrides:
      toString in class Object
      Returns:
      a string representation of this complex number of the form 42.0 - 1024.0i.