Class Vector

java.lang.Object
hoverball.math.Vector

public final class Vector
extends java.lang.Object
The class Vector represents a three dimensional vector.

Let be:
    a, b, v  -  vectors
    x, y, z  -  real numbers (as coordinates)
    r  -  real number
    c  -  complex number
    A  -  matrix
    v  -  the vector of the Vector object itself

Operator Overloading for Groovy, Scala, Kotlin and Jython is supported.

  • Field Summary

    Fields 
    Modifier and Type Field Description
    double x
    x-coordinate
    double y
    y-coordinate
    double z
    z-coordinate
  • Constructor Summary

    Constructors 
    Constructor Description
    Vector()
    Creates a vector with the coordinates (0,0,0).
    Vector​(double x, double y, double z)
    Creates a vector with the coordinates (x,y,z).
    Vector​(Complex c)
    Creates a vector from a complex number.
    Vector​(Vector v)
    Creates a vector equal to another.
  • Method Summary

    Modifier and Type Method Description
    double abs()
    Returns the absolute value  [ = | v | ].
    double abs2()
    Returns the squared absolute value  [ = | v |^2 ].
    Vector add​(Vector b)
    Adds a vector  [ v = v + b ].
    static Vector add​(Vector a, Vector b)
    Sums two vectors  [ = a + b ].
    Vector div​(double r)
    Divides by a real number  [ v = v / r ].
    static double dot​(Vector a, Vector b)
    Returns the dot product between two vectors  [ = < a, b > ].
    boolean equals​(double x, double y, double z)
    Compares with another vector  [ v = (x,y,z) ?
    boolean equals​(java.lang.Object v)
    Compares with another vector  [ v = v ?
    int hashCode()
    Returns the hash code  [ = #### ].
    Vector mul​(double r)
    Multiplies by a real number  [ v = v r ].
    Vector mul​(Matrix A)
    Multiplies by a matrix  [ v = v A ].
    static Vector mul​(Vector v, double r)
    Multiplies a vector by a real number  [ = v r ].
    static Vector mul​(Vector v, Matrix A)
    Multiplies a vector by a matrix  [ = v A ].
    Vector neg()
    Negates the vector  [ v = -v ].
    static Vector neg​(Vector v)
    Creates the negated vector  [ = -v ].
    Vector norm()
    Normalizes the absolute value to 1  [ v = v / | v | ].
    static Vector norm​(Vector v)
    Creates the normalization of the absolute value to 1  [ = v / | v | ].
    Vector sub​(Vector b)
    Substracts a vector  [ v = v - b ].
    static Vector sub​(Vector a, Vector b)
    Substracts two vectors  [ = a - b ].
    java.lang.String toString()
    String representation  [ = "..." ].
    static Vector vec​(Vector a, Vector b)
    Returns the three dimensional vector product between two vectors  [ = a x b ].
    boolean zero()
    Tests if zero  [ v = 0 ?

    Methods inherited from class java.lang.Object

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

    • x

      public final double x
      x-coordinate
    • y

      public final double y
      y-coordinate
    • z

      public final double z
      z-coordinate
  • Constructor Details

    • Vector

      public Vector()
      Creates a vector with the coordinates (0,0,0).
    • Vector

      public Vector​(double x, double y, double z)
      Creates a vector with the coordinates (x,y,z).
      Parameters:
      x - x-coordinate
      y - y-coordinate
      z - z-coordinate
    • Vector

      public Vector​(Vector v)
      Creates a vector equal to another.
      Parameters:
      v - copied vector
    • Vector

      public Vector​(Complex c)
      Creates a vector from a complex number.

      The z-coordinate of the vector is set to zero.

      Parameters:
      c - complex number
  • 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 v)
      Compares with another vector  [ v = v ? ].
      Overrides:
      equals in class java.lang.Object
      Parameters:
      v - vector
      Returns:
      the equality
    • equals

      public boolean equals​(double x, double y, double z)
      Compares with another vector  [ v = (x,y,z) ? ].
      Parameters:
      x - real number
      y - real number
      z - real number
      Returns:
      the equality
    • add

      public final Vector add​(Vector b)
      Adds a vector  [ v = v + b ].
      Parameters:
      b - vector
      Returns:
      this
    • sub

      public final Vector sub​(Vector b)
      Substracts a vector  [ v = v - b ].
      Parameters:
      b - vector
      Returns:
      this
    • mul

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

      public final Vector mul​(Matrix A)
      Multiplies by a matrix  [ v = v A ].
      Parameters:
      A - matrix
      Returns:
      this
    • div

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

      public final Vector neg()
      Negates the vector  [ v = -v ].
      Returns:
      this
    • zero

      public final boolean zero()
      Tests if zero  [ v = 0 ? ].
      Returns:
      true, if this vector equals (0,0,0)
    • abs

      public final double abs()
      Returns the absolute value  [ = | v | ].
      Returns:
      the absolute value
    • abs2

      public final double abs2()
      Returns the squared absolute value  [ = | v |^2 ].
      Returns:
      the squared absolute value
    • norm

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

      public static final Vector add​(Vector a, Vector b)
      Sums two vectors  [ = a + b ].
      Parameters:
      a - vector
      b - vector
      Returns:
      the sum
    • sub

      public static final Vector sub​(Vector a, Vector b)
      Substracts two vectors  [ = a - b ].
      Parameters:
      a - vector
      b - vector
      Returns:
      the difference
    • neg

      public static final Vector neg​(Vector v)
      Creates the negated vector  [ = -v ].
      Parameters:
      v - vector
      Returns:
      negated vector
    • norm

      public static final Vector norm​(Vector v)
      Creates the normalization of the absolute value to 1  [ = v / | v | ].
      Parameters:
      v - vector
      Returns:
      die Normierung
    • mul

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

      public static final Vector mul​(Vector v, Matrix A)
      Multiplies a vector by a matrix  [ = v A ].
      Parameters:
      v - vector
      A - matrix
      Returns:
      the product
    • dot

      public static final double dot​(Vector a, Vector b)
      Returns the dot product between two vectors  [ = < a, b > ].
      Parameters:
      a - vector
      b - vector
      Returns:
      the dot product
    • vec

      public static final Vector vec​(Vector a, Vector b)
      Returns the three dimensional vector product between two vectors  [ = a x b ].
      Parameters:
      a - vector
      b - vector
      Returns:
      the vector product