🛰️航天仿真算法库 SpaceAST 0.3.1
载入中...
搜索中...
未找到
Rotation.hpp
浏览该文件的文档.
1
20
21#pragma once
22
23#include "AstGlobal.h"
24#include "AstMath/Quaternion.hpp"
25#include "AstMath/Matrix.hpp"
26#include "AstMath/Vector.hpp"
27#include "AstMath/AngleAxis.hpp"
28#include "AstMath/AttitudeConvert.hpp"
29
30
31AST_NAMESPACE_BEGIN
32
33
34#define _AST_DEF_ROTATION_PROPERTIES\
35 const Rotation& rotation() const { return rotation_; }\
36 Rotation& rotation() { return rotation_; }\
37 const Rotation& getRotation() const { return rotation_; }\
38 Rotation& getRotation() { return rotation_; }\
39 void setRotation(const Rotation& rotation) { rotation_ = rotation; }\
40 const Matrix3d& matrix() const { return rotation_.matrix(); }\
41 Matrix3d& matrix() { return rotation_.matrix(); }\
42 const Matrix3d& getMatrix() const { return rotation_.matrix(); }\
43 Matrix3d& getMatrix() { return rotation_.matrix(); }\
44 void setMatrix(const Matrix3d& mat) { rotation_.setMatrix(mat); }\
45 Quaternion quaternion() const { return rotation_.getQuaternion(); }\
46 Quaternion getQuaternion() const { return rotation_.getQuaternion(); }\
47
48
49
55{
56public:
60 static Rotation Identity();
61
64 {
65 return *reinterpret_cast<Rotation*>(&mat);
66 }
67
69 static const Rotation& CastFrom(const Matrix3d& mat)
70 {
71 return *reinterpret_cast<const Rotation*>(&mat);
72 }
73
75 static Rotation FromMatrix(const Matrix3d& mat)
76 {
77 return Rotation(mat);
78 }
79
81 Rotation() = default;
82
85 Rotation(const Rotation& other) = default;
86
89 explicit Rotation(const Quaternion& quat);
90
93 explicit Rotation(const Matrix3d& mat);
94
98 Rotation(double angle, const Vector3d& axis);
99
100
103 explicit Rotation(const AngleAxis& aa);
104
107 const Matrix3d& getMatrix() const { return matrix_; }
108 Matrix3d& getMatrix() { return matrix_; }
109 const Matrix3d& matrix() const { return matrix_; }
110 Matrix3d& matrix() { return matrix_; }
111
114 void setMatrix(const Matrix3d& mat) { matrix_ = mat; }
115
118 Quaternion getQuaternion() const;
119
122 void setQuaternion(const Quaternion& quat);
123
126 Vector3d getAxis() const;
127
130 double getAngle() const;
131
132
136 void getAngleAxis(double& angle, Vector3d& axis) const;
137
138
142 void setAngleAxis(double angle, const Vector3d& axis);
143
146 void getAngleAxis(AngleAxis& aa) const;
147
150 void setAngleAxis(const AngleAxis& aa);
151
157 Rotation& compose(const Rotation& next);
158
163 Rotation composed(const Rotation& next) const;
164
169 Rotation operator*(const Rotation& next) const;
170
175 Rotation& operator*=(const Rotation& next);
176
179 void getInverse(Rotation& inversed) const;
180
183 Rotation inverse() const;
184
188 void transformVector(const Vector3d& vector, Vector3d& vectorOut) const;
189
190
195 void transformVectorInv(const Vector3d& vector, Vector3d& vectorOut) const;
196
200 Vector3d transformVector(const Vector3d& vector) const;
201
202
206 Vector3d transformVectorInv(const Vector3d& vector) const;
207
208protected:
209 Matrix3d matrix_{};
210};
211
212
213
214A_ALWAYS_INLINE Rotation::Rotation(const Quaternion& quat)
215{
216 aQuatToMatrix(quat, matrix_);
217}
218
219
220A_ALWAYS_INLINE Rotation::Rotation(const Matrix3d& mat)
221 : matrix_(mat)
222{
223}
224
225A_ALWAYS_INLINE Rotation::Rotation(double angle, const Vector3d &axis)
226 : Rotation(AngleAxis(angle, axis))
227{
228}
229
230A_ALWAYS_INLINE Rotation::Rotation(const AngleAxis &aa)
231 : matrix_(aa.toRotationMatrix())
232{
233}
234
236{
237 return Rotation(Matrix3d::Identity());
238}
239
240A_ALWAYS_INLINE Quaternion Rotation::getQuaternion() const
241{
242 return aMatrixToQuat(matrix_);
243}
244
245A_ALWAYS_INLINE void Rotation::setQuaternion(const Quaternion& quat)
246{
247 aQuatToMatrix(quat, matrix_);
248}
249
250A_ALWAYS_INLINE Vector3d Rotation::getAxis() const
251{
252 AngleAxis aa;
253 aMatrixToAngleAxis(matrix_, aa);
254 return aa.axis();
255}
256
257A_ALWAYS_INLINE double Rotation::getAngle() const
258{
259 AngleAxis aa;
260 aMatrixToAngleAxis(matrix_, aa);
261 return aa.angle();
262}
263
264A_ALWAYS_INLINE void Rotation::getAngleAxis(double &angle, Vector3d &axis) const
265{
266 AngleAxis aa;
267 getAngleAxis(aa);
268 axis = aa.axis();
269 angle = aa.angle();
270}
271
272A_ALWAYS_INLINE void Rotation::setAngleAxis(double angle, const Vector3d &axis)
273{
274 setAngleAxis(AngleAxis(angle, axis));
275}
276
277A_ALWAYS_INLINE void Rotation::getAngleAxis(AngleAxis &aa) const
278{
279 aMatrixToAngleAxis(matrix_, aa);
280}
281
282A_ALWAYS_INLINE void Rotation::setAngleAxis(const AngleAxis &aa)
283{
284 matrix_ = aa.toRotationMatrix();
285}
286
287A_ALWAYS_INLINE Rotation& Rotation::compose(const Rotation &next)
288{
289 matrix_ = next.matrix_ * matrix_;
290 return *this;
291}
292
293A_ALWAYS_INLINE Rotation Rotation::composed(const Rotation &next) const
294{
295 return Rotation(next.matrix_ * matrix_);
296}
297
298A_ALWAYS_INLINE Rotation Rotation::operator*(const Rotation &next) const
299{
300 return composed(next);
301}
302
303A_ALWAYS_INLINE Rotation &Rotation::operator*=(const Rotation &next)
304{
305 return compose(next);
306}
307
308A_ALWAYS_INLINE void Rotation::getInverse(Rotation &inversed) const
309{
310 inversed.matrix_ = this->matrix_.transpose();
311}
312
313A_ALWAYS_INLINE Rotation Rotation::inverse() const
314{
315 Rotation retval;
316 this->getInverse(retval);
317 return retval;
318}
319
320A_ALWAYS_INLINE void Rotation::transformVector(const Vector3d &vector, Vector3d &vectorOut) const
321{
322 vectorOut = this->matrix_ * vector;
323}
324
325A_ALWAYS_INLINE void Rotation::transformVectorInv(const Vector3d &vector, Vector3d &vectorOut) const
326{
327 vectorOut = vector * this->matrix_;
328}
329
330A_ALWAYS_INLINE Vector3d Rotation::transformVector(const Vector3d& vector) const
331{
332 Vector3d retval;
333 this->transformVector(vector, retval);
334 return retval;
335}
336
337A_ALWAYS_INLINE Vector3d Rotation::transformVectorInv(const Vector3d &vector) const
338{
339 Vector3d retval;
340 this->transformVectorInv(vector, retval);
341 return retval;
342}
343
344AST_NAMESPACE_END
轴角类
定义 AngleAxis.hpp:35
const Vector3d & axis() const
获取旋转轴
定义 AngleAxis.hpp:53
double angle() const
获取旋转角度(弧度)
定义 AngleAxis.hpp:48
Matrix3d toRotationMatrix() const
轴角转旋转矩阵
定义 AngleAxis.hpp:74
四元数
定义 Quaternion.hpp:48
坐标系旋转类
定义 Rotation.hpp:55
double getAngle() const
获取旋转角度(弧度)
定义 Rotation.hpp:257
Vector3d getAxis() const
获取旋转轴
定义 Rotation.hpp:250
void transformVector(const Vector3d &vector, Vector3d &vectorOut) const
变换向量
定义 Rotation.hpp:320
void transformVectorInv(const Vector3d &vector, Vector3d &vectorOut) const
变换向量(逆变换)
定义 Rotation.hpp:325
void getAngleAxis(double &angle, Vector3d &axis) const
获取旋转轴和角度(弧度)
定义 Rotation.hpp:264
void getInverse(Rotation &inversed) const
获取逆旋转
定义 Rotation.hpp:308
static Rotation FromMatrix(const Matrix3d &mat)
从矩阵转换为坐标系旋转对象
定义 Rotation.hpp:75
Rotation & compose(const Rotation &next)
组合下一个旋转
定义 Rotation.hpp:287
static const Rotation & CastFrom(const Matrix3d &mat)
从矩阵转换为坐标系旋转对象(常量版本)
定义 Rotation.hpp:69
Rotation()=default
坐标系旋转类默认构造函数
static Rotation Identity()
单位旋转
定义 Rotation.hpp:235
void setQuaternion(const Quaternion &quat)
设置四元数
定义 Rotation.hpp:245
const Matrix3d & getMatrix() const
获取旋转矩阵
定义 Rotation.hpp:107
Quaternion getQuaternion() const
获取四元数
定义 Rotation.hpp:240
Rotation composed(const Rotation &next) const
组合下一个旋转
定义 Rotation.hpp:293
void setMatrix(const Matrix3d &mat)
设置旋转矩阵
定义 Rotation.hpp:114
Rotation operator*(const Rotation &next) const
组合下一个旋转
定义 Rotation.hpp:298
void setAngleAxis(double angle, const Vector3d &axis)
设置轴角
定义 Rotation.hpp:272
Rotation(const Rotation &other)=default
复制构造函数
static Rotation & CastFrom(Matrix3d &mat)
从矩阵转换为坐标系旋转对象
定义 Rotation.hpp:63
Rotation inverse() const
获取逆旋转
定义 Rotation.hpp:313
Rotation & operator*=(const Rotation &next)
组合下一个旋转
定义 Rotation.hpp:303
void aQuatToMatrix(const Quaternion &quat, Matrix3d &m)
四元数转矩阵
定义 AttitudeConvert.cpp:90
void aMatrixToAngleAxis(const Matrix3d &mtx, AngleAxis &aa)
矩阵转轴角
定义 AttitudeConvert.cpp:788
void aMatrixToQuat(const Matrix3d &mtx, Quaternion &quat)
矩阵转四元数
定义 AttitudeConvert.cpp:115