Package com.stuypulse.stuylib.math
Class Angle
java.lang.Object
com.stuypulse.stuylib.math.Angle
This angle class is made to remove the ambiguity of units when passing or returning angles. It
stores it in radians, but returns it in any unit depending on what the user requests. All of the
functions and math normalize the angle to help issues.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final Angle
static final Angle
static final Angle
static final Angle
static final Angle
static final Angle
static final Angle
static final Angle
static final Angle
static final Angle
static final Angle
static final Angle
An angle that will return cos() = 0, sin() = 0, toRadians() = 0static final Angle
static final Angle
-
Method Summary
Modifier and TypeMethodDescriptionAdd two angles togetheraddDegrees
(double degrees) Add two angles togetheraddRadians
(double radians) Add two angles togetheraddRotations
(double rotations) Add two angles togetherdouble
cos()
div
(double scale) Divide the angle by a scalar valueboolean
Compare Angle to another objectstatic Angle
fromArcMinutes
(double arcminutes) Construct a new Angle class with a double in arcminutestatic Angle
fromArcSeconds
(double arcseconds) Construct a new Angle class with a double in arcsecondsstatic Angle
fromDegrees
(double degrees) Construct a new Angle class with a double in degreesstatic Angle
fromDegrees
(int degrees) Return a new Angle class with an integer in degrees.static Angle
fromRadians
(double radians) Construct a new Angle class with a double in radiansstatic Angle
fromRotation2d
(edu.wpi.first.math.geometry.Rotation2d rotation) Constructs a new Angle from a WPILib Rotation2dstatic Angle
fromRotations
(double rotations) Construct a new Angle class with a double in rotationsstatic Angle
fromSlope
(double slope) Construct a new Angle from a slope.static Angle
fromVector
(double x, double y) Contstruct a new Angle class from x and y positions.static Angle
fromVector
(Vector2D vector) Construct a new Angle class from a vector.edu.wpi.first.math.geometry.Rotation2d
Return the StuyLib Angle class in the form of the WPILib Rotation2d.int
hashCode()
mul
(double scale) Multiply the angle by a scalar valuenegative()
opposite()
double
sin()
Subtract two angles from each othersubDegrees
(double degrees) Subtract two angles from each othersubRadians
(double radians) Subtract two angles from each othersubRotations
(double rotations) Subtract two angles from each otherdouble
tan()
double
double
toDegrees
(double center) double
double
toRadians
(double center) double
double
toRotations
(double center) double
velocityDegrees
(Angle prev, double dt) Get the angular velocity in degrees/s given 2 angles and a dtdouble
velocityRadians
(Angle prev, double dt) Get the angular velocity in radians given 2 angles and a dtdouble
velocityRotations
(Angle prev, double dt) Get the angular velocity in rotations/s given 2 angles and a dt
-
Field Details
-
kRadiant
-
kDegree
-
kArcMinute
-
kArcSecond
-
kZero
-
k30deg
-
k45deg
-
k60deg
-
k90deg
-
k120deg
-
k135deg
-
k150deg
-
k180deg
-
kNull
An angle that will return cos() = 0, sin() = 0, toRadians() = 0
-
-
Method Details
-
fromRadians
Construct a new Angle class with a double in radians- Parameters:
radians
- the angle for the new angle class measured in radians- Returns:
- an angle class with the specified angle
-
fromRotations
Construct a new Angle class with a double in rotations- Parameters:
rotations
- the angle for the new angle class measured in the number of rotations- Returns:
- an angle class with the specified angle
-
fromDegrees
Construct a new Angle class with a double in degrees- Parameters:
degrees
- the angle for the new angle class measured in degrees- Returns:
- an angle class with the specified angle
-
fromDegrees
Return a new Angle class with an integer in degrees.Because the value that the angle is created from is an integer, every possible angle has been precalculated. You can use this method if you are worried about memory usage or computation time.
- Parameters:
degrees
- the angle for the new angle class in degrees- Returns:
- an angle class with the specified angle
-
fromArcMinutes
Construct a new Angle class with a double in arcminute- Parameters:
arcminutes
- the angle for the new angle class in arcminutes- Returns:
- an angle class with the specified angle
-
fromArcSeconds
Construct a new Angle class with a double in arcseconds- Parameters:
arcseconds
- the angle for the new angle class in arcseconds- Returns:
- an angle class with the specified angle
-
fromVector
Contstruct a new Angle class from x and y positions.You can think of this as getting the angle from rise [y] over run [x].
- Parameters:
x
- the run of the vectory
- the rise of the vector- Returns:
- the new angle class
-
fromVector
Construct a new Angle class from a vector.This is identicle to calling fromVector(x, y) but by passing in the vectors x and y values.
- Parameters:
vector
- the vector from which to get the angle from- Returns:
- the angle of the vector
-
fromSlope
Construct a new Angle from a slope.This will get you the angle of any slope in the form of rise / run.
- Parameters:
slope
- the slope to get the angle from- Returns:
- the angle of the slope
-
fromRotation2d
Constructs a new Angle from a WPILib Rotation2d- Parameters:
rotation
- rotation2d object- Returns:
- the same angle
-
toRadians
public double toRadians()- Returns:
- the value of the angle in radians centered around 0.0 (+/- pi)
-
toRadians
public double toRadians(double center) - Parameters:
center
- the angle in radians to be centered around (+/- pi)- Returns:
- the angle normalized around the center in radians
-
toRotations
public double toRotations()- Returns:
- the value of the angle in rotations centered around 0.0 (+/- 0.5)
-
toRotations
public double toRotations(double center) - Parameters:
center
- the angle in rotations to be centered around (+/- 0.5)- Returns:
- the angle normalized around the center in rotations
-
toDegrees
public double toDegrees()- Returns:
- the value of the angle in degrees centered around 0.0 (+/- 180)
-
toDegrees
public double toDegrees(double center) - Parameters:
center
- the angle in degrees to be centered around (+/- 180)- Returns:
- the angle normalized around the center in degrees
-
getRotation2d
public edu.wpi.first.math.geometry.Rotation2d getRotation2d()Return the StuyLib Angle class in the form of the WPILib Rotation2d.This function is here in order to make interoperability with WPILib easier so that manual conversion isn't needed as much.
- Returns:
- Rotation2d with the same value as this angle
-
add
Add two angles together- Parameters:
other
- the other angle in the sum- Returns:
- the sum of the two angles [normalized from (-pi, pi)]
-
addRadians
Add two angles together- Parameters:
radians
- the other angle in the sum- Returns:
- the sum of the two angles [normalized from (-pi, pi)]
-
addRotations
Add two angles together- Parameters:
rotations
- the other angle in the sum- Returns:
- the sum of the two angles [normalized from (-pi, pi)]
-
addDegrees
Add two angles together- Parameters:
degrees
- the other angle in the sum- Returns:
- the sum of the two angles [normalized from (-pi, pi)]
-
sub
Subtract two angles from each other- Parameters:
other
- the other angle to subtract- Returns:
- the second angle subtracted from the first [normalized from (-pi, pi)]
-
subRadians
Subtract two angles from each other- Parameters:
radians
- the other angle to subtract- Returns:
- the second angle subtracted from the first [normalized from (-pi, pi)]
-
subRotations
Subtract two angles from each other- Parameters:
rotations
- the other angle to subtract- Returns:
- the second angle subtracted from the first [normalized from (-pi, pi)]
-
subDegrees
Subtract two angles from each other- Parameters:
degrees
- the other angle to subtract- Returns:
- the second angle subtracted from the first [normalized from (-pi, pi)]
-
velocityRadians
Get the angular velocity in radians given 2 angles and a dt- Parameters:
prev
- the previous angle to measure velocity fromdt
- the time between measurements- Returns:
- the calculated angular velocity in radians/s
-
velocityRotations
Get the angular velocity in rotations/s given 2 angles and a dt- Parameters:
prev
- the previous angle to measure velocity fromdt
- the time between measurements- Returns:
- the calculated angular velocity in rotations/s
-
velocityDegrees
Get the angular velocity in degrees/s given 2 angles and a dt- Parameters:
prev
- the previous angle to measure velocity fromdt
- the time between measurements- Returns:
- the calculated angular velocity in degrees/s
-
mul
Multiply the angle by a scalar value- Parameters:
scale
- the scaler value to multiply the angle by- Returns:
- the multiplied angle [normalized from (-pi, pi)]
-
div
Divide the angle by a scalar value- Parameters:
scale
- the scaler value to divide the angle by- Returns:
- the divided angle [normalized from (-pi, pi)]
-
negative
- Returns:
- an angle with a negative value
-
opposite
- Returns:
- an angle rotated by 180 degrees or Pi radians
-
sin
public double sin()- Returns:
- the sine value of this angle
-
cos
public double cos()- Returns:
- the cosine value of this angle
-
tan
public double tan()- Returns:
- the tangent value of this angle
-
getVector
- Returns:
- the angle as a point on the unit circle
-
equals
Compare Angle to another object -
hashCode
public int hashCode()
-