Class Vector2d

java.lang.Object
me.autobot.lib.math.coordinates.Vector2d

public class Vector2d extends Object
A class representing a 2D vector.
  • Constructor Details

    • Vector2d

      public Vector2d(double x, double y)
      Creates a new vector from cartesian coordinates.
      Parameters:
      x - The x coordinate
      y - The y coordinate
  • Method Details

    • zero

      public static Vector2d zero()
      The zero vector. Equivalent to (0, 0).
      Returns:
      The zero vector.
    • fromPolar

      public static Vector2d fromPolar(double magnitude, Rotation2d rotation)
      Creates a new vector from polar coordinates.
      Parameters:
      magnitude - The magnitude of the vector.
      rotation - The rotation of the vector.
      Returns:
      The vector from polar coordinates.
    • rotateValue

      public static Vector2d rotateValue(double value, Rotation2d rotation)
      Rotates a value by a rotation, creating a vector.
      Parameters:
      value - The value to rotate.
      rotation - The rotation to rotate the value by.
      Returns:
      The rotated value as a vector.
    • getX

      public double getX()
      Gets the x coordinate of the vector.
      Returns:
      The x coordinate of the vector.
    • setX

      public void setX(double x)
      Sets the x coordinate of the vector.
      Parameters:
      x - The new x coordinate of the vector.
    • getY

      public double getY()
      Gets the y coordinate of the vector.
      Returns:
      The y coordinate of the vector.
    • setY

      public void setY(double y)
      Sets the y coordinate of the vector.
      Parameters:
      y - The new y coordinate of the vector.
    • multiply

      public Vector2d multiply(double scalar)
      Multiplies the vector by a scalar.
      Parameters:
      scalar - The scalar to multiply the vector by.
      Returns:
      The vector multiplied by the scalar.
    • add

      public Vector2d add(Vector2d other)
      Adds two vectors together.
      Parameters:
      other - The other vector to add to this vector.
      Returns:
      The sum of the two vectors.
    • subtract

      public Vector2d subtract(Vector2d other)
      Subtracts two vectors.
      Parameters:
      other - The other vector to subtract from this vector.
      Returns:
      The difference of the two vectors.
    • scale

      public Vector2d scale(double scalar)
      Scales the vector by a scalar. Equivalent to multiplying the vector by a scalar.
      Parameters:
      scalar - The scalar to scale the vector by.
      Returns:
      The scaled vector.
    • dot

      public double dot(Vector2d other)
      Gets the dot product of two vectors.
      Parameters:
      other - The other vector to dot this vector with.
      Returns:
      The dot product of the two vectors.
    • cross

      public double cross(Vector2d other)
      Gets the cross product of two vectors.
      Parameters:
      other - The other vector to cross this vector with.
      Returns:
      The cross product of the two vectors.
    • magnitude

      public double magnitude()
      Gets the magnitude of the vector.
      Returns:
      The magnitude of the vector.
    • rotate

      public Vector2d rotate(Rotation2d rotation)
      Rotates the vector by a rotation.
      Parameters:
      rotation - The rotation to rotate the vector by.
      Returns:
      The rotated vector.
    • normalize

      public Vector2d normalize()
      Normalizes the vector.
      Returns:
      The normalized vector.
    • angle

      public double angle(Vector2d other)
      Gets the angle between two vectors.
      Parameters:
      other - The other vector to get the angle between.
      Returns:
      The angle between the two vectors.
    • angle

      public Rotation2d angle()
      Gets the angle of the vector.
      Returns:
      The angle of the vector.
    • distance

      public double distance(Vector2d other)
      Gets the distance between two vectors.
      Parameters:
      other - The other vector to get the distance between.
      Returns:
      The distance between the two vectors.
    • toInt2

      public Int2 toInt2()
      Converts the vector to a 2D integer vector.
      Returns:
      The vector as a 2D integer vector.
    • perpendicular

      public Vector2d perpendicular()
      Gets the perpendicular vector of the vector.
      Returns:
      The perpendicular vector of the vector.
    • toString

      public String toString()
      Gets the string representation of the vector.
      Overrides:
      toString in class Object
    • clone

      public Vector2d clone()
      Clones the vector.
      Overrides:
      clone in class Object
      Returns:
      The cloned vector.