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

    Fields 
    Modifier and Type Field Description
    static java.text.DecimalFormat format
    DecimalFormat object for string conversion.
    double x
    x-coordinate of the complex number.
    double y
    y-coordinate of the complex number.
  • 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 ?

    Methods inherited from class java.lang.Object

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

    • format

      public static java.text.DecimalFormat format
      DecimalFormat object for string conversion.

      This object is used for formatting all objects of this package. The default format is 0.### with Locale.US.

    • x

      public final double x
      x-coordinate of the complex number.
    • y

      public final double y
      y-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-coordinate
      y - y-coordinate
    • Complex

      public Complex​(double x)
      Creates a complex number with the coordinates (x,0).
      Parameters:
      x - x-coordinate
    • Complex

      public Complex​(Complex c)
      Creates a complex number equal to another.
      Parameters:
      c - copied complex number
    • Complex

      public Complex​(Vector v)
      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 class java.lang.Object
      Returns:
      the hash code
    • toString

      public java.lang.String toString()
      String representation  [ = "..." ].
      Overrides:
      toString in class java.lang.Object
      Returns:
      the string
    • equals

      public boolean equals​(java.lang.Object c)
      Compares with a complex number  [ c = c ? ].
      Overrides:
      equals in class java.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 number
      y - real number
      Returns:
      the equality
    • add

      public final Complex add​(Complex b)
      Adds a complex number  [ c = c + b ].
      Parameters:
      b - complex number
      Returns:
      this
    • sub

      public final Complex sub​(Complex b)
      Substracts a complex number  [ c = c - b ].
      Parameters:
      b - complex number
      Returns:
      this
    • mul

      public final Complex mul​(double r)
      Multiplies by a real number  [ c = c r ].
      Parameters:
      r - real number
      Returns:
      this
    • mul

      public final Complex mul​(Complex b)
      Multiplies by a complex number  [ c = c b ].
      Parameters:
      b - complex number
      Returns:
      this
    • div

      public final Complex div​(double r)
      Divides by a real number  [ c = c / r ].
      Parameters:
      r - real number
      Returns:
      this
    • div

      public final Complex div​(Complex b)
      Divides by a complex number  [ c = c / b ].
      Parameters:
      b - complex number
      Returns:
      this
    • inv

      public final Complex inv()
      Builds the inverse number  [ c = 1 / c ].
      Returns:
      this
    • neg

      public final Complex neg()
      Builds the negated number  [ c = -c ].
      Returns:
      this
    • conj

      public final Complex 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

      public final Complex norm()
      Normalizes the absolute value to 1  [ c = c / | c | ].
      Returns:
      this
    • add

      public static final Complex add​(Complex a, Complex b)
      Sums two complex numbers  [ = a + b ].
      Parameters:
      a - complex number
      b - complex number
      Returns:
      the sum
    • sub

      public static final Complex sub​(Complex a, Complex b)
      Substracts two complex numbers  [ = a - b ].
      Parameters:
      a - complex number
      b - complex number
      Returns:
      the difference
    • neg

      public static final Complex neg​(Complex c)
      Creates the negated number  [ = -c ].
      Parameters:
      c - complex number
      Returns:
      the negated number
    • inv

      public static final Complex inv​(Complex c)
      Creates the inverse number  [ = 1 / c ].
      Parameters:
      c - complex number
      Returns:
      die inverse number
    • conj

      public static final Complex conj​(Complex c)
      Creates the conjugate  [ = c ].
      Parameters:
      c - complex number
      Returns:
      the conjugate
    • norm

      public static final Complex norm​(Complex c)
      Creates the normalization of the complex number to 1.  [ = c / | c | ].
      Parameters:
      c - complex number
      Returns:
      the normalization
    • mul

      public static final Complex mul​(Complex c, double r)
      Multiplies a complex number by a real number.  [ = c r ].
      Parameters:
      c - complex number
      r - real number
      Returns:
      the product
    • mul

      public static final Complex mul​(Complex a, Complex b)
      Multiplies two complex numbers.  [ = a b ].
      Parameters:
      a - complex number
      b - complex number
      Returns:
      the complex product
    • dot

      public static final double dot​(Complex a, Complex b)
      Returns the dot product between two complex numbers.  [ = < a, b > ].
      Parameters:
      a - complex number
      b - complex number
      Returns:
      the dot product
    • vec

      public static final double vec​(Complex a, Complex b)
      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 number
      b - complex number
      Returns:
      the z-coordinate of the vector product
    • vec

      public static final Complex vec​(double a_z, Complex b)
      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 number
      b - complex number
      Returns:
      the (x,y)-coordinates of the vector product
    • expi

      public static final Complex expi​(double y)
      Returns the value of the complex exponential function  [ = exp iy ].
      Parameters:
      y - real number
      Returns:
      the exponential value
    • exp

      public static final Complex exp​(Complex a)
      Returns the value of the complex exponential function  [ = exp a ].
      Parameters:
      a - complex number
      Returns:
      the exponential value