Package me.autobot.lib.math.coordinates
Class Polar
java.lang.Object
me.autobot.lib.math.coordinates.Polar
Polar coordinates represent a vector by its magnitude and the angle it makes with the x-axis.
-
Constructor Summary
ConstructorsConstructorDescriptionPolar
(double r, Rotation2d theta) Constructs a Polar object with the given magnitude and angle. -
Method Summary
Modifier and TypeMethodDescriptiondouble
cos()
Returns the x-component of the vector, calculated as r * cos(theta).double
Returns the angle of the vector in degrees.double
getR()
Returns the magnitude of the vector (the radius value).double
Returns the angle of the vector in radians.getTheta()
Returns the angle of the vector.inverse()
Returns the inverse of the vector, with the same magnitude and the opposite angle.normal()
Gets the normal of the vector, with the same magnitude (this implies a 90 degree rotation).rotateBy
(Rotation2d other) Rotates the vector by the given angle.void
setR
(double r) Sets the magnitude of the vector (the radius value).void
setTheta
(Rotation2d theta) Sets the angle of the vector.double
sin()
Returns the y-component of the vector, calculated as r * sin(theta).double
tan()
Returns the tangent of the vector, calculated as sin(theta) / cos(theta).toVector()
Converts the Polar object to a Vector2d object.
-
Constructor Details
-
Polar
Constructs a Polar object with the given magnitude and angle.- Parameters:
r
- The magnitude of the vector. This is the distance from the origin to the point.theta
- The angle of the vector. This is the angle the vector makes with the x-axis.
-
-
Method Details
-
getR
public double getR()Returns the magnitude of the vector (the radius value).- Returns:
- The magnitude of the vector.
-
setR
public void setR(double r) Sets the magnitude of the vector (the radius value).- Parameters:
r
- The new magnitude of the vector.
-
getTheta
Returns the angle of the vector.- Returns:
- The angle of the vector.
-
setTheta
Sets the angle of the vector.- Parameters:
theta
- The new angle of the vector.
-
rotateBy
Rotates the vector by the given angle.- Parameters:
other
- The angle by which to rotate the vector.- Returns:
- The vector rotated by the given angle.
-
normal
Gets the normal of the vector, with the same magnitude (this implies a 90 degree rotation).- Returns:
- The normal of the vector.
-
inverse
Returns the inverse of the vector, with the same magnitude and the opposite angle.- Returns:
- The inverse of the vector.
-
cos
public double cos()Returns the x-component of the vector, calculated as r * cos(theta).- Returns:
- The x-component of the vector (cos(theta) * r).
-
sin
public double sin()Returns the y-component of the vector, calculated as r * sin(theta).- Returns:
- The y-component of the vector (sin(theta) * r).
-
tan
public double tan()Returns the tangent of the vector, calculated as sin(theta) / cos(theta).- Returns:
- The tangent of the vector (sin(theta) / cos(theta)).
-
getRadians
public double getRadians()Returns the angle of the vector in radians.- Returns:
- The angle of the vector in radians.
-
getDegrees
public double getDegrees()Returns the angle of the vector in degrees.- Returns:
- The angle of the vector in degrees.
-
toVector
Converts the Polar object to a Vector2d object.- Returns:
- The Vector2d object equivalent to the Polar object.
-