mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[wpimath] Add CoordinateSystem conversion for Transform3d (#4443)
I also refactored Pose3d's conversion implementation to use the Translation3d and Rotation3d conversions, thereby giving Translation3d and Rotation3d test coverage. No changes were made to the expected values of the Pose3d conversion tests. The expected values of the Transform3d conversion tests were copied from the Pose3d conversion tests without modification.
This commit is contained in:
@@ -110,6 +110,21 @@ public class CoordinateSystem {
|
||||
* @return The given pose in the desired coordinate system.
|
||||
*/
|
||||
public static Pose3d convert(Pose3d pose, CoordinateSystem from, CoordinateSystem to) {
|
||||
return pose.relativeTo(new Pose3d(new Translation3d(), to.m_rotation.minus(from.m_rotation)));
|
||||
return new Pose3d(
|
||||
convert(pose.getTranslation(), from, to), convert(pose.getRotation(), from, to));
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given transform from one coordinate system to another.
|
||||
*
|
||||
* @param transform The transform to convert.
|
||||
* @param from The coordinate system the transform starts in.
|
||||
* @param to The coordinate system to which to convert.
|
||||
* @return The given transform in the desired coordinate system.
|
||||
*/
|
||||
public static Transform3d convert(
|
||||
Transform3d transform, CoordinateSystem from, CoordinateSystem to) {
|
||||
return new Transform3d(
|
||||
convert(transform.getTranslation(), from, to), convert(transform.getRotation(), from, to));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user