This repository has been archived by the owner on Jul 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor constraints to use geometry classes
- Loading branch information
Showing
28 changed files
with
978 additions
and
495 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// Copyright (c) TrajoptLib contributors | ||
|
||
#pragma once | ||
|
||
#include <utility> | ||
|
||
#include <sleipnir/autodiff/Variable.hpp> | ||
|
||
#include "trajopt/geometry/Rotation2.hpp" | ||
#include "trajopt/geometry/Translation2.hpp" | ||
|
||
namespace trajopt { | ||
|
||
/** | ||
* Represents a 2D pose with translation and rotation. | ||
*/ | ||
template <typename T> | ||
class Pose2 { | ||
public: | ||
/** | ||
* Constructs a pose at the origin facing toward the positive x-axis. | ||
*/ | ||
constexpr Pose2() = default; | ||
|
||
/** | ||
* Constructs a pose with the specified translation and rotation. | ||
* | ||
* @param translation The translational component of the pose. | ||
* @param rotation The rotational component of the pose. | ||
*/ | ||
constexpr Pose2(Translation2<T> translation, Rotation2<T> rotation) | ||
: m_translation{std::move(translation)}, | ||
m_rotation{std::move(rotation)} {} | ||
|
||
/** | ||
* Constructs a pose with x and y translations instead of a separate | ||
* translation. | ||
* | ||
* @param x The x component of the translational component of the pose. | ||
* @param y The y component of the translational component of the pose. | ||
* @param rotation The rotational component of the pose. | ||
*/ | ||
constexpr Pose2(T x, T y, Rotation2<T> rotation) | ||
: m_translation{Translation2<T>{std::move(x), std::move(y)}}, | ||
m_rotation{std::move(rotation)} {} | ||
|
||
/** | ||
* Coerces one pose type into another. | ||
* | ||
* @param other The other pose type. | ||
*/ | ||
template <typename U> | ||
constexpr explicit Pose2(const Pose2<U>& other) | ||
: m_translation{other.Translation()}, m_rotation{other.Rotation()} {} | ||
|
||
/** | ||
* Returns the underlying translation. | ||
* | ||
* @return Reference to the translational component of the pose. | ||
*/ | ||
constexpr const Translation2<T>& Translation() const { return m_translation; } | ||
|
||
/** | ||
* Returns the X component of the pose's translation. | ||
* | ||
* @return The x component of the pose's translation. | ||
*/ | ||
constexpr const T& X() const { return m_translation.X(); } | ||
|
||
/** | ||
* Returns the Y component of the pose's translation. | ||
* | ||
* @return The y component of the pose's translation. | ||
*/ | ||
constexpr const T& Y() const { return m_translation.Y(); } | ||
|
||
/** | ||
* Returns the underlying rotation. | ||
* | ||
* @return Reference to the rotational component of the pose. | ||
*/ | ||
constexpr const Rotation2<T>& Rotation() const { return m_rotation; } | ||
|
||
/** | ||
* Rotates the pose around the origin and returns the new pose. | ||
* | ||
* @param other The rotation to transform the pose by. | ||
* @return The rotated pose. | ||
*/ | ||
constexpr Pose2<T> RotateBy(const Rotation2<T>& other) const { | ||
return {m_translation.RotateBy(other), m_rotation.RotateBy(other)}; | ||
} | ||
|
||
private: | ||
Translation2<T> m_translation; | ||
Rotation2<T> m_rotation; | ||
}; | ||
|
||
using Pose2d = Pose2<double>; | ||
using Pose2v = Pose2<sleipnir::Variable>; | ||
|
||
} // namespace trajopt |
Oops, something went wrong.