🛰️航天仿真算法库 SpaceAST 0.0.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
39{
40public:
44 static Rotation Identity();
45
48 {
49 return *reinterpret_cast<Rotation*>(&mat);
50 }
51
53 static const Rotation& CastFrom(const Matrix3d& mat)
54 {
55 return *reinterpret_cast<const Rotation*>(&mat);
56 }
57
59 static Rotation FromMatrix(const Matrix3d& mat)
60 {
61 return Rotation(mat);
62 }
63
65 Rotation() = default;
66
69 Rotation(const Rotation& other) = default;
70
73 Rotation(const Quaternion& quat);
74
77 Rotation(const Matrix3d& mat);
78
82 Rotation(double angle, const Vector3d& axis);
83
84
87 Rotation(const AngleAxis& aa);
88
91 const Matrix3d& getMatrix() const { return matrix_; }
92 Matrix3d& getMatrix() { return matrix_; }
93
96 void setMatrix(const Matrix3d& mat) { matrix_ = mat; }
97
100 Quaternion getQuaternion() const;
101
104 void setQuaternion(const Quaternion& quat);
105
108 Vector3d getAxis() const;
109
112 double getAngle() const;
113
114
118 void getAngleAxis(double& angle, Vector3d& axis) const;
119
120
124 void setAngleAxis(double angle, const Vector3d& axis);
125
128 void getAngleAxis(AngleAxis& aa) const;
129
132 void setAngleAxis(const AngleAxis& aa);
133
139 Rotation& compose(const Rotation& next);
140
145 Rotation composed(const Rotation& next) const;
146
151 Rotation operator*(const Rotation& next) const;
152
157 Rotation& operator*=(const Rotation& next);
158
161 void getInverse(Rotation& inversed) const;
162
165 Rotation inverse() const;
166
170 void transformVector(const Vector3d& vector, Vector3d& vectorOut) const;
171
172
177 void transformVectorInv(const Vector3d& vector, Vector3d& vectorOut) const;
178
182 Vector3d transformVector(const Vector3d& vector) const;
183
184
188 Vector3d transformVectorInv(const Vector3d& vector) const;
189
190protected:
191 Matrix3d matrix_;
192};
193
194
195
196A_ALWAYS_INLINE Rotation::Rotation(const Quaternion& quat)
197{
198 aQuatToMatrix(quat, matrix_);
199}
200
201
202A_ALWAYS_INLINE Rotation::Rotation(const Matrix3d& mat)
203 : matrix_(mat)
204{
205}
206
207A_ALWAYS_INLINE Rotation::Rotation(double angle, const Vector3d &axis)
208 : Rotation(AngleAxis(angle, axis))
209{
210}
211
212A_ALWAYS_INLINE Rotation::Rotation(const AngleAxis &aa)
213 : matrix_(aa.toRotationMatrix())
214{
215}
216
218{
219 return Rotation(Matrix3d::Identity());
220}
221
222A_ALWAYS_INLINE Quaternion Rotation::getQuaternion() const
223{
224 return aMatrixToQuat(matrix_);
225}
226
227A_ALWAYS_INLINE void Rotation::setQuaternion(const Quaternion& quat)
228{
229 aQuatToMatrix(quat, matrix_);
230}
231
232A_ALWAYS_INLINE Vector3d Rotation::getAxis() const
233{
234 AngleAxis aa;
235 aMatrixToAngleAxis(matrix_, aa);
236 return aa.axis();
237}
238
239A_ALWAYS_INLINE double Rotation::getAngle() const
240{
241 AngleAxis aa;
242 aMatrixToAngleAxis(matrix_, aa);
243 return aa.angle();
244}
245
246A_ALWAYS_INLINE void Rotation::getAngleAxis(double &angle, Vector3d &axis) const
247{
248 AngleAxis aa;
249 getAngleAxis(aa);
250 axis = aa.axis();
251 angle = aa.angle();
252}
253
254A_ALWAYS_INLINE void Rotation::setAngleAxis(double angle, const Vector3d &axis)
255{
256 setAngleAxis(AngleAxis(angle, axis));
257}
258
259A_ALWAYS_INLINE void Rotation::getAngleAxis(AngleAxis &aa) const
260{
261 aMatrixToAngleAxis(matrix_, aa);
262}
263
264A_ALWAYS_INLINE void Rotation::setAngleAxis(const AngleAxis &aa)
265{
266 matrix_ = aa.toRotationMatrix();
267}
268
269A_ALWAYS_INLINE Rotation& Rotation::compose(const Rotation &next)
270{
271 matrix_ = next.matrix_ * matrix_;
272 return *this;
273}
274
275A_ALWAYS_INLINE Rotation Rotation::composed(const Rotation &next) const
276{
277 return Rotation(next.matrix_ * matrix_);
278}
279
280A_ALWAYS_INLINE Rotation Rotation::operator*(const Rotation &next) const
281{
282 return composed(next);
283}
284
285A_ALWAYS_INLINE Rotation &Rotation::operator*=(const Rotation &next)
286{
287 return compose(next);
288}
289
290A_ALWAYS_INLINE void Rotation::getInverse(Rotation &inversed) const
291{
292 inversed.matrix_ = this->matrix_.transpose();
293}
294
295A_ALWAYS_INLINE Rotation Rotation::inverse() const
296{
297 Rotation retval;
298 this->getInverse(retval);
299 return retval;
300}
301
302A_ALWAYS_INLINE void Rotation::transformVector(const Vector3d &vector, Vector3d &vectorOut) const
303{
304 vectorOut = this->matrix_ * vector;
305}
306
307A_ALWAYS_INLINE void Rotation::transformVectorInv(const Vector3d &vector, Vector3d &vectorOut) const
308{
309 vectorOut = vector * this->matrix_;
310}
311
312A_ALWAYS_INLINE Vector3d Rotation::transformVector(const Vector3d& vector) const
313{
314 Vector3d retval;
315 this->transformVector(vector, retval);
316 return retval;
317}
318
319A_ALWAYS_INLINE Vector3d Rotation::transformVectorInv(const Vector3d &vector) const
320{
321 Vector3d retval;
322 this->transformVectorInv(vector, retval);
323 return retval;
324}
325
326AST_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:47
坐标系旋转类
定义 Rotation.hpp:39
double getAngle() const
获取旋转角度(弧度)
定义 Rotation.hpp:239
Vector3d getAxis() const
获取旋转轴
定义 Rotation.hpp:232
void transformVector(const Vector3d &vector, Vector3d &vectorOut) const
变换向量
定义 Rotation.hpp:302
void transformVectorInv(const Vector3d &vector, Vector3d &vectorOut) const
变换向量(逆变换)
定义 Rotation.hpp:307
void getAngleAxis(double &angle, Vector3d &axis) const
获取旋转轴和角度(弧度)
定义 Rotation.hpp:246
void getInverse(Rotation &inversed) const
获取逆旋转
定义 Rotation.hpp:290
static Rotation FromMatrix(const Matrix3d &mat)
从矩阵转换为坐标系旋转对象
定义 Rotation.hpp:59
Rotation & compose(const Rotation &next)
组合下一个旋转
定义 Rotation.hpp:269
static const Rotation & CastFrom(const Matrix3d &mat)
从矩阵转换为坐标系旋转对象(常量版本)
定义 Rotation.hpp:53
Rotation()=default
坐标系旋转类默认构造函数
static Rotation Identity()
单位旋转
定义 Rotation.hpp:217
void setQuaternion(const Quaternion &quat)
设置四元数
定义 Rotation.hpp:227
const Matrix3d & getMatrix() const
获取旋转矩阵
定义 Rotation.hpp:91
Quaternion getQuaternion() const
获取四元数
定义 Rotation.hpp:222
Rotation composed(const Rotation &next) const
组合下一个旋转
定义 Rotation.hpp:275
void setMatrix(const Matrix3d &mat)
设置旋转矩阵
定义 Rotation.hpp:96
Rotation operator*(const Rotation &next) const
组合下一个旋转
定义 Rotation.hpp:280
void setAngleAxis(double angle, const Vector3d &axis)
设置轴角
定义 Rotation.hpp:254
Rotation(const Rotation &other)=default
复制构造函数
static Rotation & CastFrom(Matrix3d &mat)
从矩阵转换为坐标系旋转对象
定义 Rotation.hpp:47
Rotation inverse() const
获取逆旋转
定义 Rotation.hpp:295
Rotation & operator*=(const Rotation &next)
组合下一个旋转
定义 Rotation.hpp:285
void aQuatToMatrix(const Quaternion &quat, Matrix3d &m)
四元数转矩阵
定义 AttitudeConvert.cpp:90
void aMatrixToAngleAxis(const Matrix3d &mtx, AngleAxis &aa)
矩阵转轴角
定义 AttitudeConvert.cpp:743
void aMatrixToQuat(const Matrix3d &mtx, Quaternion &quat)
矩阵转四元数
定义 AttitudeConvert.cpp:115