Package frc.team1711.swerve.util
Class Vector
- java.lang.Object
-
- frc.team1711.swerve.util.Vector
-
public class Vector extends java.lang.Object
A vector class used bySwerveDrive
for calculating target velocities and rotational positions.
-
-
Constructor Summary
Constructors Constructor Description Vector(double x, double y)
Makes a new vector.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Vector
add(Vector v2)
Adds a vector and returns the summed vector.static Vector
fromPolarDegrees(double direction, double magnitude)
Creates a new vector with the specifieddirection
andmagnitude
.static Vector
fromPolarRadians(double direction, double magnitude)
Creates a new vector with the specifieddirection
andmagnitude
.double
getMagnitude()
double
getRotationDegrees()
double
getRotationRadians()
double
getX()
double
getY()
Vector
reflectAcrossX()
Reflects across the x axis.Vector
reflectAcrossY()
Reflects across the y axis.Vector
scale(double s)
Scales this vector and returns the resulting vector.Vector
subtract(Vector v2)
Subtracts a vector and returns the difference vector.Vector
toRotationDegrees(double degrees)
Rotates this vector to a given rotation.Vector
toRotationRadians(double radians)
Rotates this vector to a given rotation.java.lang.String
toString()
-
-
-
Field Detail
-
ZERO
public static final Vector ZERO
The vector (0, 0).
-
-
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 specifieddirection
andmagnitude
.- 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 specifieddirection
andmagnitude
.- Parameters:
direction
- The direction of the vector, in radians, starting directly right of the origin on the x axis and progressing counterclockwisemagnitude
- 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 classjava.lang.Object
-
-