🛰️航天仿真算法库 SpaceAST 0.3.1
载入中...
搜索中...
未找到
Transform.hpp
浏览该文件的文档.
1
20
21#pragma once
22
23#include "AstGlobal.h"
24#include "AstMath/Rotation.hpp"
25
26AST_NAMESPACE_BEGIN
27
28
29#define _AST_DEF_TRANSFORM_PROPERTIES\
30 const Vector3d& translation() const { return translation_; }\
31 Vector3d& translation() { return translation_; }\
32 const Vector3d& getTranslation() const { return translation_; }\
33 Vector3d& getTranslation() { return translation_; }\
34 void setTranslation(const Vector3d& translation) { translation_ = translation; }\
35
40{
41public:
42
44 Transform() = default;
45
47 Transform(const Vector3d& trans, const Rotation& rot);
48
52 static Transform Identity();
53
54 _AST_DEF_TRANSFORM_PROPERTIES
55 _AST_DEF_ROTATION_PROPERTIES
56
57
61 Transform& compose(const Transform& next);
62
67 Transform composed(const Transform& next) const;
68
73 Transform operator*(const Transform& next) const;
74
79 Transform& operator*=(const Transform& next);
80
83 void getInverse(Transform& inversed) const;
84
87 Transform inverse() const;
88
90 void setIdentity() { rotation_ = Rotation::Identity(); translation_ = Vector3d::Zero(); }
91
95 void transformPosition(const Vector3d& position, Vector3d& positionOut) const;
96
100 Vector3d transformPosition(const Vector3d& position) const;
101
102protected:
103 Vector3d translation_{};
104 Rotation rotation_{};
105};
106
107A_ALWAYS_INLINE Transform::Transform(const Vector3d &trans, const Rotation &rot)
108 : translation_(trans), rotation_(rot)
109{
110}
111
113{
114 return Transform(Vector3d::Zero(), Rotation::Identity());
115}
116
117A_ALWAYS_INLINE Transform &Transform::compose(const Transform &next)
118{
119 translation_ += next.translation() * matrix();
120 rotation_ = rotation_.composed(next.rotation());
121 return *this;
122}
123
124A_ALWAYS_INLINE Transform Transform::composed(const Transform &next) const
125{
129 return Transform(
130 translation_ + next.translation() * matrix(),
131 rotation_.composed(next.rotation())
132 );
133}
134
135A_ALWAYS_INLINE Transform Transform::operator*(const Transform &next) const
136{
137 return this->composed(next);
138}
139
140A_ALWAYS_INLINE Transform &Transform::operator*=(const Transform &next)
141{
142 return this->compose(next);
143}
144
145A_ALWAYS_INLINE void Transform::getInverse(Transform &inversed) const
146{
147 rotation_.transformVector(-translation_, inversed.translation());
148 rotation_.getInverse(inversed.rotation());
149}
150
151A_ALWAYS_INLINE Transform Transform::inverse() const
152{
153 Transform retval;
154 this->getInverse(retval);
155 return retval;
156}
157
158A_ALWAYS_INLINE void Transform::transformPosition(const Vector3d &position, Vector3d &positionOut) const
159{
163 rotation_.transformVector(position - translation_, positionOut);
164}
165
166A_ALWAYS_INLINE Vector3d Transform::transformPosition(const Vector3d &position) const
167{
168 Vector3d retval;
169 this->transformPosition(position, retval);
170 return retval;
171}
172
173AST_NAMESPACE_END
坐标系旋转类
定义 Rotation.hpp:55
void transformVector(const Vector3d &vector, Vector3d &vectorOut) const
变换向量
定义 Rotation.hpp:320
void getInverse(Rotation &inversed) const
获取逆旋转
定义 Rotation.hpp:308
static Rotation Identity()
单位旋转
定义 Rotation.hpp:235
Rotation composed(const Rotation &next) const
组合下一个旋转
定义 Rotation.hpp:293
坐标系转换类
定义 Transform.hpp:40
Transform operator*(const Transform &next) const
组合下一个坐标系转换
定义 Transform.hpp:135
_AST_DEF_TRANSFORM_PROPERTIES _AST_DEF_ROTATION_PROPERTIES Transform & compose(const Transform &next)
组合下一个坐标系转换
定义 Transform.hpp:117
void transformPosition(const Vector3d &position, Vector3d &positionOut) const
转换位置
定义 Transform.hpp:158
Rotation rotation_
旋转
定义 Transform.hpp:104
Transform composed(const Transform &next) const
组合下一个坐标系转换
定义 Transform.hpp:124
void setIdentity()
设置为单位转换
定义 Transform.hpp:90
Vector3d translation_
平移
定义 Transform.hpp:103
void getInverse(Transform &inversed) const
获取逆转换
定义 Transform.hpp:145
static Transform Identity()
获取单位转换
定义 Transform.hpp:112
Transform()=default
转换默认构造函数
Transform inverse() const
获取逆转换
定义 Transform.hpp:151
Transform & operator*=(const Transform &next)
组合下一个坐标系转换
定义 Transform.hpp:140