mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-27 02:01:42 +00:00
[wpimath] Add Rotation2d.fromRadians factory (#4178)
This commit is contained in:
@@ -58,6 +58,16 @@ public class Rotation2d implements Interpolatable<Rotation2d> {
|
||||
m_value = Math.atan2(m_sin, m_cos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs and returns a Rotation2d with the given radian value.
|
||||
*
|
||||
* @param radians The value of the angle in degrees.
|
||||
* @return The rotation object with the desired angle value.
|
||||
*/
|
||||
public static Rotation2d fromRadians(double radians) {
|
||||
return new Rotation2d(radians);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs and returns a Rotation2d with the given degree value.
|
||||
*
|
||||
|
||||
@@ -15,8 +15,8 @@ class Rotation2dTest {
|
||||
|
||||
@Test
|
||||
void testRadiansToDegrees() {
|
||||
var rot1 = new Rotation2d(Math.PI / 3);
|
||||
var rot2 = new Rotation2d(Math.PI / 4);
|
||||
var rot1 = Rotation2d.fromRadians(Math.PI / 3);
|
||||
var rot2 = Rotation2d.fromRadians(Math.PI / 4);
|
||||
|
||||
assertAll(
|
||||
() -> assertEquals(rot1.getDegrees(), 60.0, kEpsilon),
|
||||
|
||||
Reference in New Issue
Block a user