Class Vector2D


  • public class Vector2D
    extends java.lang.Object
    Represents a 2D vector with many math utility functions. Immutable. Follows the standard cartesian frame of reference, with angle 0 on the positive x axis and increasing counterclockwise. On the robot, the positive x axis is pointing forwards, while the positive y axis is pointing to the left.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static Vector2D ORIGIN  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Vector2D changeAngle​(WrappedAngle angle)
      Creates a new Vector2D that is a copy of this one, except with the given angle.
      Vector2D changeMagnitude​(double magnitude)
      Creates a new Vector2D that is a copy of this one, except with the given magnitude.
      Vector2D changeX​(double x)
      Creates a new Vector2D that is a copy of this one, except with the given x component.
      Vector2D changeY​(double y)
      Creates a new Vector2D that is a copy of this one, except with the given y component.
      static Vector2D createCartesianCoordinates​(double x, double y)
      Creates a Vector2D using the given cartesian coordinates.
      static Vector2D createPolarCoordinates​(double magnitude, WrappedAngle angle)
      Creates a vector2D using the given polar coordinates.
      WrappedAngle getAngle()
      Get the angle of this vector.
      double getMagnitude()
      Get the magnitude of this vector.
      double getX()
      Get the x component of this vector.
      double getY()
      Get the y component of this vector.
      Vector2D limitChange​(Vector2D desired, double maxChange)
      Limits the magnitude of the difference between this vector and the returned vector when trying to go from this vector to the desired vector.
      Vector2D plus​(Vector2D that)
      Returns this vector added to the given vector.
      Vector2D rotate​(double angle)
      Returns this vector rotated by the given angle
      Vector2D times​(double scalar)
      Returns this vector multiplied by the given scalar.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • ORIGIN

        public static final Vector2D ORIGIN
    • Method Detail

      • getX

        public double getX()
        Get the x component of this vector.
        Returns:
        The x component
      • getY

        public double getY()
        Get the y component of this vector.
        Returns:
        The y component
      • getMagnitude

        public double getMagnitude()
        Get the magnitude of this vector.
        Returns:
        The magnitude
      • getAngle

        public WrappedAngle getAngle()
        Get the angle of this vector.
        Returns:
        The angle
      • createCartesianCoordinates

        public static Vector2D createCartesianCoordinates​(double x,
                                                          double y)
        Creates a Vector2D using the given cartesian coordinates.
        Parameters:
        x - The x component
        y - The y component
        Returns:
        The created vector
      • createPolarCoordinates

        public static Vector2D createPolarCoordinates​(double magnitude,
                                                      WrappedAngle angle)
        Creates a vector2D using the given polar coordinates.
        Parameters:
        magnitude - The magnitude
        angle - The angle, in degrees
        Returns:
        The created vector
      • changeX

        public Vector2D changeX​(double x)
        Creates a new Vector2D that is a copy of this one, except with the given x component.
        Parameters:
        x - The x component for the new vector
        Returns:
        The changed vector
      • changeY

        public Vector2D changeY​(double y)
        Creates a new Vector2D that is a copy of this one, except with the given y component.
        Parameters:
        y - The y component for the new vector
        Returns:
        The changed vector
      • changeMagnitude

        public Vector2D changeMagnitude​(double magnitude)
        Creates a new Vector2D that is a copy of this one, except with the given magnitude.
        Parameters:
        magnitude - The magnitude for the new vector
        Returns:
        The changed vector
      • changeAngle

        public Vector2D changeAngle​(WrappedAngle angle)
        Creates a new Vector2D that is a copy of this one, except with the given angle.
        Parameters:
        angle - The angle for the new vector
        Returns:
        The changed vector
      • plus

        public Vector2D plus​(Vector2D that)
        Returns this vector added to the given vector.
        Parameters:
        that - The vector the add to this vector
        Returns:
        The sum
      • times

        public Vector2D times​(double scalar)
        Returns this vector multiplied by the given scalar.
        Parameters:
        scalar - The scalar multiplicand
        Returns:
        The product
      • rotate

        public Vector2D rotate​(double angle)
        Returns this vector rotated by the given angle
        Parameters:
        angle - The angle offset
        Returns:
        The rotated vector
      • limitChange

        public Vector2D limitChange​(Vector2D desired,
                                    double maxChange)
        Limits the magnitude of the difference between this vector and the returned vector when trying to go from this vector to the desired vector.
        Parameters:
        desired - The desired vector
        maxChange - The maximum amount that the returned vector can differ from this vector
        Returns:
        The vector that is as close to the desired vector as possible without exceeing the maximum change