Class Vector3D

java.lang.Object
org.chsrobotics.lib.math.geometry.Vector3D
Direct Known Subclasses:
Vector2D

public class Vector3D extends Object
Represents a 3-dimensional vector in a right-handed system.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Vector3D(double x, double y, double z)
    Constructs a 3-dimensional vector.
  • Method Summary

    Modifier and Type
    Method
    Description
    add(Vector3D other)
    Adds two vectors.
    Performs the cross product operation (sum of the perpindicular component vectors) between two vectors.
    double
    Performs the dot product operation (sum of the product of parallel component vector signed magnitudes) between two vectors.
    boolean
    equals(Object other)
     
    double
    Returns the magnitude of the vector as an unsigned (always positive) double.
    double
    Returns the X (i-hat, positive to the horizontal right on a graph) component of the vector.
    double
    Returns the Y (j-hat, positive up vertically on a graph) component of the vector.
    double
    Returns the Z (k-hat, positive out of the graph) component of the vector.
    int
     
    scalarDivide(double scalar)
    Divides the vector by a scalar.
    scalarMultiply(double scalar)
    Multiplies the vector by a scalar.
    Subtracts two vectors.
     

    Methods inherited from class java.lang.Object

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

    • Vector3D

      public Vector3D(double x, double y, double z)
      Constructs a 3-dimensional vector.
      Parameters:
      x - The signed X (i-hat, positive to the horizontal right on a graph) component of the vector.
      y - The signed Y (j-hat, positive up vertically on a graph) component of the vector.
      z - The signed Z (k-hat, positive out of the graph) component of the vector.
  • Method Details

    • getMagnitude

      public double getMagnitude()
      Returns the magnitude of the vector as an unsigned (always positive) double.
      Returns:
      The unsigned magnitude.
    • add

      public Vector3D add(Vector3D other)
      Adds two vectors.
      Parameters:
      other - The other vector (order does not matter).
      Returns:
      The result of vector addition.
    • subtract

      public Vector3D subtract(Vector3D other)
      Subtracts two vectors.
      Parameters:
      other - The other vector.
      Returns:
      The result of vector subtraction.
    • dotProduct

      public double dotProduct(Vector3D other)
      Performs the dot product operation (sum of the product of parallel component vector signed magnitudes) between two vectors.
      Parameters:
      other - The other vector (order does not matter).
      Returns:
      The scalar result of the dot product.
    • crossProduct

      public Vector3D crossProduct(Vector3D other)
      Performs the cross product operation (sum of the perpindicular component vectors) between two vectors.
      Parameters:
      other - The other vector (order *does* matter).
      Returns:
      The result of the cross product.
    • scalarMultiply

      public Vector3D scalarMultiply(double scalar)
      Multiplies the vector by a scalar.
      Parameters:
      scalar - The double scalar to multiply by.
      Returns:
      The result of the multiplication operation.
    • scalarDivide

      public Vector3D scalarDivide(double scalar)
      Divides the vector by a scalar. If scalar is 0, will return this vector unchanged.
      Parameters:
      scalar - The double scalar to divide by.
      Returns:
      The result of the division operation.
    • getX

      public double getX()
      Returns the X (i-hat, positive to the horizontal right on a graph) component of the vector.
      Returns:
      The signed X component.
    • getY

      public double getY()
      Returns the Y (j-hat, positive up vertically on a graph) component of the vector.
      Returns:
      The signed Y component.
    • getZ

      public double getZ()
      Returns the Z (k-hat, positive out of the graph) component of the vector.
      Returns:
      The signed Z component.
    • equals

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

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object