Class Vector

java.lang.Object
xyz.jeremynoesen.pseudo3d.core.util.Vector

public class Vector
extends java.lang.Object
Immutable Vector with vector mathematical operators
  • Constructor Summary

    Constructors
    Constructor Description
    Vector()
    Create a new Vector
    Vector​(float x, float y)
    Create a new 2D Vector with components x and y
    Vector​(float x, float y, float z)
    Create a new 3D Vector with components x, y, and z
    Vector​(Vector vector)
    Copy constructor for Vector
  • Method Summary

    Modifier and Type Method Description
    Vector add​(Vector... vector)
    Add together this Vector and other Vectors
    float angleBetween​(Vector vector)
    Get the angle between two Vectors in degrees
    Vector cross​(Vector vector)
    Cross multiply two Vectors
    float distance​(Vector vector)
    Calculate the distance between the ends of two Vectors
    Vector divide​(float scale)
    Divide a Vector's magnitude by a scalar, which divides each component by the scalar
    Vector divide​(Vector... vector)
    Divide Vector components by other Vectors' components
    float dot​(Vector vector)
    Calculate the dot product of two Vectors
    boolean equals​(java.lang.Object vector)
    Check if two Vectors are equal
    float get​(Axis axis)
    Get a specified component of the Vector
    float getMagnitude()
    Get the magnitude of the Vector
    float getX()
    Get the x component of the Vector
    float getY()
    Get the y component of the Vector
    float getZ()
    Get the z component of the Vector
    Vector multiply​(float scale)
    Multiply a Vector's magnitude by a scalar, which multiplies each component by the scalar
    Vector multiply​(Vector... vector)
    Multiply vector Components by other Vectors' components
    Vector normalize()
    Normalize the Vector (a Vector of magnitude 1)
    Vector set​(Axis axis, float value)
    Set a specified component of the Vector
    Vector setX​(float x)
    Set the x component of the Vector
    Vector setY​(float y)
    Set the y component of the Vector
    Vector setZ​(float z)
    Set the z component of the Vector
    Vector subtract​(Vector... vector)
    Subtract Vectors from this Vector
    java.lang.String toString()
    Get the Vector as a String

    Methods inherited from class java.lang.Object

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

    • Vector

      public Vector()
      Create a new Vector
    • Vector

      public Vector​(float x, float y, float z)
      Create a new 3D Vector with components x, y, and z
      Parameters:
      x - X component of Vector
      y - Y component of Vector
      z - Z component of Vector
    • Vector

      public Vector​(float x, float y)
      Create a new 2D Vector with components x and y
      Parameters:
      x - X component of Vector
      y - Y component of Vector
    • Vector

      public Vector​(Vector vector)
      Copy constructor for Vector
      Parameters:
      vector - Vector to copy
  • Method Details

    • getX

      public float getX()
      Get the x component of the Vector
      Returns:
      X component
    • setX

      public Vector setX​(float x)
      Set the x component of the Vector
      Parameters:
      x - X component
      Returns:
      Vector with modified x component
    • getY

      public float getY()
      Get the y component of the Vector
      Returns:
      Y component
    • setY

      public Vector setY​(float y)
      Set the y component of the Vector
      Parameters:
      y - Y component
      Returns:
      Vector with modified y component
    • getZ

      public float getZ()
      Get the z component of the Vector
      Returns:
      Z component
    • setZ

      public Vector setZ​(float z)
      Set the z component of the Vector
      Parameters:
      z - Z component
      Returns:
      Vector with modified y component
    • get

      public float get​(Axis axis)
      Get a specified component of the Vector
      Parameters:
      axis - Axis to get value for
      Returns:
      Component of Vector based on Axis
    • set

      public Vector set​(Axis axis, float value)
      Set a specified component of the Vector
      Parameters:
      axis - Axis to set value to
      value - Value to set
      Returns:
      Modified Vector
    • getMagnitude

      public float getMagnitude()
      Get the magnitude of the Vector
      Returns:
      Magnitude of Vector
    • add

      public Vector add​(Vector... vector)
      Add together this Vector and other Vectors
      Parameters:
      vector - Vectors to add
      Returns:
      Vector from the sum of the Vectors
    • subtract

      public Vector subtract​(Vector... vector)
      Subtract Vectors from this Vector
      Parameters:
      vector - Vectors to subtract
      Returns:
      Vector from subtraction of the Vectors
    • multiply

      public Vector multiply​(Vector... vector)
      Multiply vector Components by other Vectors' components
      Parameters:
      vector - Vectors to multiply
      Returns:
      Vector from multiplication of the Vectors
    • multiply

      public Vector multiply​(float scale)
      Multiply a Vector's magnitude by a scalar, which multiplies each component by the scalar
      Parameters:
      scale - What to scale the Vector by
      Returns:
      Scaled Vector
    • divide

      public Vector divide​(Vector... vector)
      Divide Vector components by other Vectors' components
      Parameters:
      vector - Vectors to divide
      Returns:
      Vector from division of the Vectors
    • divide

      public Vector divide​(float scale)
      Divide a Vector's magnitude by a scalar, which divides each component by the scalar
      Parameters:
      scale - What to scale the Vector by
      Returns:
      Scaled Vector
    • dot

      public float dot​(Vector vector)
      Calculate the dot product of two Vectors
      Parameters:
      vector - Vector to dot product
      Returns:
      Value of the dot product
    • cross

      public Vector cross​(Vector vector)
      Cross multiply two Vectors
      Parameters:
      vector - Vector to cross multiply
      Returns:
      Vector calculated from cross multiplication
    • distance

      public float distance​(Vector vector)
      Calculate the distance between the ends of two Vectors
      Parameters:
      vector - Vector to calculate distance to
      Returns:
      Distance to location
    • normalize

      public Vector normalize()
      Normalize the Vector (a Vector of magnitude 1)
      Returns:
      Normalized Vector
    • angleBetween

      public float angleBetween​(Vector vector)
      Get the angle between two Vectors in degrees
      Parameters:
      vector - Vector to get angle between
      Returns:
      Angle between two Vectors
    • toString

      public java.lang.String toString()
      Get the Vector as a String
      Overrides:
      toString in class java.lang.Object
      Returns:
      Vector as a String in vector format
    • equals

      public boolean equals​(java.lang.Object vector)
      Check if two Vectors are equal
      Overrides:
      equals in class java.lang.Object
      Parameters:
      vector - Vector to compare to this Vector
      Returns:
      True if the Vectors are equal