Package com.stuypulse.stuylib.math
Class Vector2D
java.lang.Object
com.stuypulse.stuylib.math.Vector2D
A Vector2D class that stores x and y position data. It is made to work with the StuyLib Angle
class and be easy to use. It is a standard Vector2D class with all of the functions that you
would expect.
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionclamp
(double maxMagnitude) limit the magnitude of a vector to a maximumdouble
double
distance()
double
div
(double divisor) double
boolean
getAngle()
double[]
getArray()
edu.wpi.first.math.geometry.Translation2d
Return the StuyLib Vector2D class in the form as WPILib's Translation2d.double
mul
(double multiplier) negative()
pow
(double power)
-
Field Details
-
kOrigin
-
kI
-
kJ
-
x
public final double xThe x position of the Vector2D -
y
public final double yThe y position of the Vector2D
-
-
Constructor Details
-
Vector2D
public Vector2D(double x, double y) - Parameters:
x
- the x axis of the vectory
- the y axis of the vector
-
Vector2D
public Vector2D(double[] axis) - Parameters:
axis
- Array of size 2 where the first element will be defined as x, and the second will be defined as y.
-
Vector2D
public Vector2D(edu.wpi.first.math.geometry.Translation2d translation) - Parameters:
translation
- Translation2d to copy this vector into
-
-
Method Details
-
getArray
public double[] getArray()- Returns:
- double array of size 2 defined as {x, y}
-
getTranslation2d
public edu.wpi.first.math.geometry.Translation2d getTranslation2d()Return the StuyLib Vector2D class in the form as WPILib's Translation2d.This function is here in order to make interoperability with WPILib easier so that manual conversion isn't needed as much.
- Returns:
- Translation2d class with the same value as the Vector2d
-
distance
- Parameters:
other
- other Vector2D- Returns:
- the distance between the two Vector2Ds
-
distance
public double distance()- Returns:
- distance from 0, 0
-
magnitude
public double magnitude()- Returns:
- magnitude of the vector (same as distance from 0, 0)
-
getAngle
- Returns:
- the angle of the Vector2D around 0, 0
-
rotate
- Parameters:
angle
- angle to rotate byorigin
- point to rotate around- Returns:
- result of rotation
-
rotate
- Parameters:
angle
- angle to rotate by- Returns:
- result of rotation
-
add
- Parameters:
other
- Vector2D to be added by- Returns:
- sum of the two Vector2Ds
-
sub
- Parameters:
other
- Vector2D to be subtracted from- Returns:
- difference between the two Vector2Ds
-
mul
- Parameters:
other
- Vector2D to be multiplied by- Returns:
- product of the two Vector2Ds
-
div
- Parameters:
other
- Vector2D to be divided by- Returns:
- division of the two Vector2Ds
-
mul
- Parameters:
multiplier
- amount to multiply the x and y components by- Returns:
- result of multiplying the x and y components by the multiplier
-
div
- Parameters:
divisor
- amount to divide the x and y components by- Returns:
- result of dividing the x and y components by the divisor
-
pow
- Parameters:
power
- power to raise magnitude of vector to- Returns:
- result of raising the magnitude of the vector to the power
-
dot
- Parameters:
other
- Vector2D to perform dot product with- Returns:
- result of performing the dot product with the other Vector2D
-
cross
- Parameters:
other
- Vector3D to perform cross product with- Returns:
- result of performing the cross product with the other Vector2D
-
normalize
- Returns:
- result of normalizing the Vector2D so that the magnitude is 1.0
-
clamp
limit the magnitude of a vector to a maximum- Parameters:
maxMagnitude
- max magitude of resulting vector- Returns:
- vector with limited magnitude
-
negative
- Returns:
- result of negating the x and y components
-
equals
-