Package util

Class Vector3D

java.lang.Object
util.Vector3D

public class Vector3D extends Object
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected double[]
    The 3 components of the vector in an array
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create a vector where all components are set to zero
    Vector3D(double[] arr)
    Create a vector where the components are set to a 3-dimensional array
    Vector3D(double x, double y, double z)
    Create a vector where the components are set to the parameters
  • Method Summary

    Modifier and Type
    Method
    Description
    add(Vector3D other)
    Adds a vector to the current vector Returns a new Vector
    void
    Adds a vector to the current vector Modifies the current vector
    double
    Get the distance from the current vector to another vector
    double
    dot(Vector3D other)
    Returns the scalar product of this and another vector
    boolean
     
    double
    Gets the magnitude of the vector
    double
    Return the x component of the vector
    double
    Return the y component of the vector
    double
    Return the z component of the vector
    int
     
    void
    multLocal(double scalar)
    Scalar multiply the current vector with a number Changes the current vector
    void
    set(int i, double num)
    Method to set the vectors components
    void
    setMag(double new_mag)
    Sets the magnitude of the vector
    sub(Vector3D other)
    Subtracts the other vector from this one Returns a new Vecotr
    Helper function to show the vector on the console
    static Vector3D
    Returns a zero vector (identity operation)

    Methods inherited from class java.lang.Object

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

    • vector

      protected double[] vector
      The 3 components of the vector in an array
  • Constructor Details

    • Vector3D

      public Vector3D()
      Create a vector where all components are set to zero
    • Vector3D

      public Vector3D(double x, double y, double z)
      Create a vector where the components are set to the parameters
      Parameters:
      x - the desired x component of the vector
      y - the desired y component of the vector
      z - the desired z component of the vector
    • Vector3D

      public Vector3D(double[] arr)
      Create a vector where the components are set to a 3-dimensional array
      Parameters:
      arr - the vector as a 3d array
  • Method Details

    • zero

      public static Vector3D zero()
      Returns a zero vector (identity operation)
      Returns:
      the zero vector
    • set

      public void set(int i, double num)
      Method to set the vectors components
      Parameters:
      i - the position of the component
      num - the desired value of the component
    • getX

      public double getX()
      Return the x component of the vector
      Returns:
      the x component of the vector
    • getY

      public double getY()
      Return the y component of the vector
      Returns:
      the y component of the vector
    • getZ

      public double getZ()
      Return the z component of the vector
      Returns:
      the z component of the vector
    • getMag

      public double getMag()
      Gets the magnitude of the vector
      Returns:
      the magnitude of the vector
    • setMag

      public void setMag(double new_mag)
      Sets the magnitude of the vector
      Parameters:
      new_mag - the desired magnitude
    • addLocal

      public void addLocal(Vector3D other)
      Adds a vector to the current vector Modifies the current vector
      Parameters:
      other - the other vector to be added to this one
    • add

      public Vector3D add(Vector3D other)
      Adds a vector to the current vector Returns a new Vector
      Parameters:
      other - the other vector to be added to this one
      Returns:
      the new vector
    • sub

      public Vector3D sub(Vector3D other)
      Subtracts the other vector from this one Returns a new Vecotr
      Parameters:
      other - the other vector
      Returns:
      the new vector
    • dot

      public double dot(Vector3D other)
      Returns the scalar product of this and another vector
      Parameters:
      other - the other vector
      Returns:
      the scalar
    • multLocal

      public void multLocal(double scalar)
      Scalar multiply the current vector with a number Changes the current vector
      Parameters:
      scalar - the scalar
    • distTo

      public double distTo(Vector3D other)
      Get the distance from the current vector to another vector
      Parameters:
      other - the other vector
      Returns:
      the distance from the current to the other vector
    • toString

      public String toString()
      Helper function to show the vector on the console
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object