mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-25 01:41:43 +00:00
[wpimath] Add 2D to 3D geometry constructors (#7380)
This commit is contained in:
@@ -58,6 +58,8 @@ class WPILIB_DLLEXPORT Pose3d {
|
||||
* Constructs a 3D pose from a 2D pose in the X-Y plane.
|
||||
*
|
||||
* @param pose The 2D pose.
|
||||
* @see Rotation3d(Rotation2d)
|
||||
* @see Translation3d(Translation2d)
|
||||
*/
|
||||
constexpr explicit Pose3d(const Pose2d& pose)
|
||||
: m_translation{pose.X(), pose.Y(), 0_m},
|
||||
|
||||
@@ -229,6 +229,16 @@ class WPILIB_DLLEXPORT Rotation3d {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a 3D rotation from a 2D rotation in the X-Y plane.
|
||||
*
|
||||
* @param rotation The 2D rotation.
|
||||
* @see Pose3d(Pose2d)
|
||||
* @see Transform3d(Transform2d)
|
||||
*/
|
||||
constexpr explicit Rotation3d(const Rotation2d& rotation)
|
||||
: Rotation3d{0_rad, 0_rad, rotation.Radians()} {}
|
||||
|
||||
/**
|
||||
* Adds two rotations together.
|
||||
*
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include <wpi/SymbolExports.h>
|
||||
|
||||
#include "frc/geometry/Transform2d.h"
|
||||
#include "frc/geometry/Translation3d.h"
|
||||
|
||||
namespace frc {
|
||||
@@ -55,6 +56,17 @@ class WPILIB_DLLEXPORT Transform3d {
|
||||
*/
|
||||
constexpr Transform3d() = default;
|
||||
|
||||
/**
|
||||
* Constructs a 3D transform from a 2D transform in the X-Y plane.
|
||||
**
|
||||
* @param transform The 2D transform.
|
||||
* @see Rotation3d(Rotation2d)
|
||||
* @see Translation3d(Translation2d)
|
||||
*/
|
||||
constexpr explicit Transform3d(const frc::Transform2d& transform)
|
||||
: m_translation{frc::Translation3d{transform.Translation()}},
|
||||
m_rotation{frc::Rotation3d{transform.Rotation()}} {}
|
||||
|
||||
/**
|
||||
* Returns the translation component of the transformation.
|
||||
*
|
||||
|
||||
@@ -66,6 +66,16 @@ class WPILIB_DLLEXPORT Translation3d {
|
||||
m_y{units::meter_t{vector.y()}},
|
||||
m_z{units::meter_t{vector.z()}} {}
|
||||
|
||||
/**
|
||||
* Constructs a 3D translation from a 2D translation in the X-Y plane.
|
||||
*
|
||||
* @param translation The 2D translation.
|
||||
* @see Pose3d(Pose2d)
|
||||
* @see Transform3d(Transform2d)
|
||||
*/
|
||||
constexpr explicit Translation3d(const Translation2d& translation)
|
||||
: Translation3d{translation.X(), translation.Y(), 0_m} {}
|
||||
|
||||
/**
|
||||
* Calculates the distance between two translations in 3D space.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user