Class Vector2D

java.lang.Object
com.stuypulse.stuylib.math.Vector2D

public final class Vector2D extends Object
A Vector2D class that stores x and y position data. It is made to work with the StuyLib Angle class and be easy to use. It is a standard Vector2D class with all of the functions that you would expect.
  • Field Details

    • kOrigin

      public static final Vector2D kOrigin
    • kI

      public static final Vector2D kI
    • kJ

      public static final Vector2D kJ
    • x

      public final double x
      The x position of the Vector2D
    • y

      public final double y
      The y position of the Vector2D
  • Constructor Details

    • Vector2D

      public Vector2D(double x, double y)
      Parameters:
      x - the x axis of the vector
      y - the y axis of the vector
    • Vector2D

      public Vector2D(double[] axis)
      Parameters:
      axis - Array of size 2 where the first element will be defined as x, and the second will be defined as y.
    • Vector2D

      public Vector2D(edu.wpi.first.math.geometry.Translation2d translation)
      Parameters:
      translation - Translation2d to copy this vector into
  • Method Details

    • getArray

      public double[] getArray()
      Returns:
      double array of size 2 defined as {x, y}
    • getTranslation2d

      public edu.wpi.first.math.geometry.Translation2d getTranslation2d()
      Return the StuyLib Vector2D class in the form as WPILib's Translation2d.

      This function is here in order to make interoperability with WPILib easier so that manual conversion isn't needed as much.

      Returns:
      Translation2d class with the same value as the Vector2d
    • distance

      public double distance(Vector2D other)
      Parameters:
      other - other Vector2D
      Returns:
      the distance between the two Vector2Ds
    • distance

      public double distance()
      Returns:
      distance from 0, 0
    • magnitude

      public double magnitude()
      Returns:
      magnitude of the vector (same as distance from 0, 0)
    • getAngle

      public Angle getAngle()
      Returns:
      the angle of the Vector2D around 0, 0
    • rotate

      public Vector2D rotate(Angle angle, Vector2D origin)
      Parameters:
      angle - angle to rotate by
      origin - point to rotate around
      Returns:
      result of rotation
    • rotate

      public Vector2D rotate(Angle angle)
      Parameters:
      angle - angle to rotate by
      Returns:
      result of rotation
    • add

      public Vector2D add(Vector2D other)
      Parameters:
      other - Vector2D to be added by
      Returns:
      sum of the two Vector2Ds
    • sub

      public Vector2D sub(Vector2D other)
      Parameters:
      other - Vector2D to be subtracted from
      Returns:
      difference between the two Vector2Ds
    • mul

      public Vector2D mul(Vector2D other)
      Parameters:
      other - Vector2D to be multiplied by
      Returns:
      product of the two Vector2Ds
    • div

      public Vector2D div(Vector2D other)
      Parameters:
      other - Vector2D to be divided by
      Returns:
      division of the two Vector2Ds
    • mul

      public Vector2D mul(double multiplier)
      Parameters:
      multiplier - amount to multiply the x and y components by
      Returns:
      result of multiplying the x and y components by the multiplier
    • div

      public Vector2D div(double divisor)
      Parameters:
      divisor - amount to divide the x and y components by
      Returns:
      result of dividing the x and y components by the divisor
    • pow

      public Vector2D pow(double power)
      Parameters:
      power - power to raise magnitude of vector to
      Returns:
      result of raising the magnitude of the vector to the power
    • dot

      public double dot(Vector2D other)
      Parameters:
      other - Vector2D to perform dot product with
      Returns:
      result of performing the dot product with the other Vector2D
    • cross

      public double cross(Vector2D other)
      Parameters:
      other - Vector3D to perform cross product with
      Returns:
      result of performing the cross product with the other Vector2D
    • normalize

      public Vector2D normalize()
      Returns:
      result of normalizing the Vector2D so that the magnitude is 1.0
    • clamp

      public Vector2D clamp(double maxMagnitude)
      limit the magnitude of a vector to a maximum
      Parameters:
      maxMagnitude - max magitude of resulting vector
      Returns:
      vector with limited magnitude
    • negative

      public Vector2D negative()
      Returns:
      result of negating the x and y components
    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object
      Parameters:
      other - object to compare to
      Returns:
      both objects are Vector2Ds and they equal eachother