Package me.autobot.lib.math.coordinates
Class Vector2d
java.lang.Object
me.autobot.lib.math.coordinates.Vector2d
A class representing a 2D vector.
-
Constructor Summary
ConstructorsConstructorDescriptionVector2d
(double x, double y) Creates a new vector from cartesian coordinates. -
Method Summary
Modifier and TypeMethodDescriptionAdds two vectors together.angle()
Gets the angle of the vector.double
Gets the angle between two vectors.clone()
Clones the vector.double
Gets the cross product of two vectors.double
Gets the distance between two vectors.double
Gets the dot product of two vectors.static Vector2d
fromPolar
(double magnitude, Rotation2d rotation) Creates a new vector from polar coordinates.double
getX()
Gets the x coordinate of the vector.double
getY()
Gets the y coordinate of the vector.double
Gets the magnitude of the vector.multiply
(double scalar) Multiplies the vector by a scalar.Normalizes the vector.Gets the perpendicular vector of the vector.rotate
(Rotation2d rotation) Rotates the vector by a rotation.static Vector2d
rotateValue
(double value, Rotation2d rotation) Rotates a value by a rotation, creating a vector.scale
(double scalar) Scales the vector by a scalar.void
setX
(double x) Sets the x coordinate of the vector.void
setY
(double y) Sets the y coordinate of the vector.Subtracts two vectors.toInt2()
Converts the vector to a 2D integer vector.toString()
Gets the string representation of the vector.static Vector2d
zero()
The zero vector.
-
Constructor Details
-
Vector2d
public Vector2d(double x, double y) Creates a new vector from cartesian coordinates.- Parameters:
x
- The x coordinatey
- The y coordinate
-
-
Method Details
-
zero
The zero vector. Equivalent to (0, 0).- Returns:
- The zero vector.
-
fromPolar
Creates a new vector from polar coordinates.- Parameters:
magnitude
- The magnitude of the vector.rotation
- The rotation of the vector.- Returns:
- The vector from polar coordinates.
-
rotateValue
Rotates a value by a rotation, creating a vector.- Parameters:
value
- The value to rotate.rotation
- The rotation to rotate the value by.- Returns:
- The rotated value as a vector.
-
getX
public double getX()Gets the x coordinate of the vector.- Returns:
- The x coordinate of the vector.
-
setX
public void setX(double x) Sets the x coordinate of the vector.- Parameters:
x
- The new x coordinate of the vector.
-
getY
public double getY()Gets the y coordinate of the vector.- Returns:
- The y coordinate of the vector.
-
setY
public void setY(double y) Sets the y coordinate of the vector.- Parameters:
y
- The new y coordinate of the vector.
-
multiply
Multiplies the vector by a scalar.- Parameters:
scalar
- The scalar to multiply the vector by.- Returns:
- The vector multiplied by the scalar.
-
add
Adds two vectors together.- Parameters:
other
- The other vector to add to this vector.- Returns:
- The sum of the two vectors.
-
subtract
Subtracts two vectors.- Parameters:
other
- The other vector to subtract from this vector.- Returns:
- The difference of the two vectors.
-
scale
Scales the vector by a scalar. Equivalent to multiplying the vector by a scalar.- Parameters:
scalar
- The scalar to scale the vector by.- Returns:
- The scaled vector.
-
dot
Gets the dot product of two vectors.- Parameters:
other
- The other vector to dot this vector with.- Returns:
- The dot product of the two vectors.
-
cross
Gets the cross product of two vectors.- Parameters:
other
- The other vector to cross this vector with.- Returns:
- The cross product of the two vectors.
-
magnitude
public double magnitude()Gets the magnitude of the vector.- Returns:
- The magnitude of the vector.
-
rotate
Rotates the vector by a rotation.- Parameters:
rotation
- The rotation to rotate the vector by.- Returns:
- The rotated vector.
-
normalize
Normalizes the vector.- Returns:
- The normalized vector.
-
angle
Gets the angle between two vectors.- Parameters:
other
- The other vector to get the angle between.- Returns:
- The angle between the two vectors.
-
angle
Gets the angle of the vector.- Returns:
- The angle of the vector.
-
distance
Gets the distance between two vectors.- Parameters:
other
- The other vector to get the distance between.- Returns:
- The distance between the two vectors.
-
toInt2
Converts the vector to a 2D integer vector.- Returns:
- The vector as a 2D integer vector.
-
perpendicular
Gets the perpendicular vector of the vector.- Returns:
- The perpendicular vector of the vector.
-
toString
Gets the string representation of the vector. -
clone
Clones the vector.
-