Class Vector


  • public class Vector
    extends java.lang.Object
    A vector class used by SwerveDrive for calculating target velocities and rotational positions.
    • Field Detail

      • ZERO

        public static final Vector ZERO
        The vector (0, 0).
    • Constructor Detail

      • Vector

        public Vector​(double x,
                      double y)
        Makes a new vector.
        Parameters:
        x - The x component of the vector
        y - The y component of the vector
    • Method Detail

      • getX

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

        public double getY()
        Returns:
        The y component of the vector
      • toRotationRadians

        public Vector toRotationRadians​(double radians)
        Rotates this vector to a given rotation.
        Parameters:
        radians - The rotation of the new vector, in radians, progressing counterclockwise starting directly to the right of the origin on the x axis.
        Returns:
        The new rotated vector
      • toRotationDegrees

        public Vector toRotationDegrees​(double degrees)
        Rotates this vector to a given rotation.
        Parameters:
        degrees - The rotation of the new vector, in degrees, progressing clockwise starting directly above the origin on the y axis.
        Returns:
        The new rotated vector
      • fromPolarDegrees

        public static Vector fromPolarDegrees​(double direction,
                                              double magnitude)
        Creates a new vector with the specified direction and magnitude.
        Parameters:
        direction - The direction of the vector, in degrees, starting directly above the origin on the y axis and progressing clockwise.
        magnitude - The magnitude of the vector
        Returns:
        The vector
      • fromPolarRadians

        public static Vector fromPolarRadians​(double direction,
                                              double magnitude)
        Creates a new vector with the specified direction and magnitude.
        Parameters:
        direction - The direction of the vector, in radians, starting directly right of the origin on the x axis and progressing counterclockwise
        magnitude - The magnitude of the vector
        Returns:
        The vector
      • add

        public Vector add​(Vector v2)
        Adds a vector and returns the summed vector.
        Parameters:
        v2 - The vector to add
        Returns:
        The summed vector
      • subtract

        public Vector subtract​(Vector v2)
        Subtracts a vector and returns the difference vector.
        Parameters:
        v2 - The vector to subtract
        Returns:
        The difference vector
      • scale

        public Vector scale​(double s)
        Scales this vector and returns the resulting vector.
        Parameters:
        s - The scalar
        Returns:
        The scaled vector
      • reflectAcrossX

        public Vector reflectAcrossX()
        Reflects across the x axis.
        Returns:
        The result of reflecting this vector across the x axis.
      • reflectAcrossY

        public Vector reflectAcrossY()
        Reflects across the y axis.
        Returns:
        The result of reflecting this vector across the y axis.
      • getRotationRadians

        public double getRotationRadians()
        Returns:
        The counterclockwise rotation, in radians, with directly right of the origin having a rotation of 0, in the range [0, 2pi).
      • getRotationDegrees

        public double getRotationDegrees()
        Returns:
        The clockwise rotation, in degrees, with directly above the origin having a rotation of 0, in the range [0, 360).
      • getMagnitude

        public double getMagnitude()
        Returns:
        The magnitude of the vector
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object