[wpimath] Add Translation2d.getAngle() (#4217)

Co-authored-by: Max Gordon <tonald.drump2.0@gamil.com>
Co-authored-by: Tyler Veness <calcmogul@gmail.com>
This commit is contained in:
Max Gordon
2022-05-15 00:22:00 -04:00
committed by GitHub
parent d364bbd5a7
commit a3d44a1e69
3 changed files with 20 additions and 0 deletions

View File

@@ -24,6 +24,10 @@ units::meter_t Translation2d::Norm() const {
return units::math::hypot(m_x, m_y);
}
Rotation2d Translation2d::Angle() const {
return Rotation2d{m_x.value(), m_y.value()};
}
Translation2d Translation2d::RotateBy(const Rotation2d& other) const {
return {m_x * other.Cos() - m_y * other.Sin(),
m_x * other.Sin() + m_y * other.Cos()};

View File

@@ -80,6 +80,13 @@ class WPILIB_DLLEXPORT Translation2d {
*/
units::meter_t Norm() const;
/**
* Returns the angle this translation forms with the positive X axis.
*
* @return The angle of the translation
*/
Rotation2d Angle() const;
/**
* Applies a rotation to the translation in 2D space.
*