Package xbot.common.math
Class XYPair
java.lang.Object
xbot.common.math.XYPair
- All Implemented Interfaces:
StructSerializable
,WPISerializable
Pair of X and Y coordinates. Can be used for points, vectors, or anything
else that requires a coordinate pair.
-
Field Summary
-
Constructor Summary
ConstructorDescriptionXYPair()
Create a coordinate at the origin.XYPair
(double x, double y) Create a coordinate with the specified x and y value.XYPair
(Rotation2d rotation) Creates a coordinate representing the unit vector for a rotation. -
Method Summary
Modifier and TypeMethodDescriptionAdds the value of a second coordinate to the current coordinate.addMagnitude
(double magnitudeToAdd) Add the magnitude to the vector represented by the coordinate.clone()
Clone the objectdouble
dotProduct
(XYPair otherPoint) Calculate the dot-product between this and another point.static XYPair
fromPolar
(double angle, double magnitude) Create a coordinate from an angle and magnitudestatic XYPair
fromUnitPolar
(double angle) Create a coordinate of magnitude 1 with an angledouble
getAngle()
Get the angle of the vector in degreesdouble
getDistanceToPoint
(XYPair otherPoint) Get the distance between the current point and a second point.double
Get the magnitude of the vector (i.e.rotate
(double angle) Rotates the vector by a given angle.scale
(double scalarMagnitude) Scales the current coordinate by a magnitude equally in both dimensions.scale
(double xMagnitude, double yMagnitude) Scales the coordinate by an x- and y- magnitude.toString()
-
Field Details
-
ZERO
-
x
public double x -
y
public double y -
struct
Translation2d struct for serialization.
-
-
Constructor Details
-
XYPair
public XYPair(double x, double y) Create a coordinate with the specified x and y value.- Parameters:
x
- the x value to usey
- the y value to use
-
XYPair
Creates a coordinate representing the unit vector for a rotation.- Parameters:
rotation
- The rotation value.
-
XYPair
public XYPair()Create a coordinate at the origin.
-
-
Method Details
-
clone
Clone the object -
fromPolar
Create a coordinate from an angle and magnitude- Parameters:
angle
- angle in degreesmagnitude
- magnitude- Returns:
- coordinate
-
fromUnitPolar
Create a coordinate of magnitude 1 with an angle- Parameters:
angle
- angle in degrees- Returns:
- coordinate
-
scale
Scales the current coordinate by a magnitude equally in both dimensions.- Parameters:
scalarMagnitude
- the magnitude to scale the coordinate by- Returns:
- the scaled object
-
scale
Scales the coordinate by an x- and y- magnitude.- Parameters:
xMagnitude
- the magnitude to scale the x-coordinate byyMagnitude
- the magnitude to scale the y-coordinate by- Returns:
- the scaled object
-
addMagnitude
Add the magnitude to the vector represented by the coordinate.- Parameters:
magnitudeToAdd
- magnitude to add- Returns:
- the modified coordinate
-
rotate
Rotates the vector by a given angle.- Parameters:
angle
- the angle in degrees to rotate the pair by- Returns:
- the rotated object
-
getAngle
public double getAngle()Get the angle of the vector in degrees- Returns:
- angle in degrees
-
getMagnitude
public double getMagnitude()Get the magnitude of the vector (i.e. distance from origin to the coordinate).- Returns:
- magnitude
-
add
Adds the value of a second coordinate to the current coordinate.- Parameters:
pair
- coordinate to add- Returns:
- the combined object
-
getDistanceToPoint
Get the distance between the current point and a second point.- Parameters:
otherPoint
- the point to calculate the distance from- Returns:
- the distance
-
dotProduct
Calculate the dot-product between this and another point.- Parameters:
otherPoint
- the second point to use for calculating dot product- Returns:
- the dot product value
-
toString
-
toTranslation2d
-