🛰️航天仿真算法库 SpaceAST 0.3.1
载入中...
搜索中...
未找到
AccelerationRotation.hpp
浏览该文件的文档.
1
20
21#pragma once
22
23#include "AstGlobal.h"
24#include "KinematicRotation.hpp"
25
26AST_NAMESPACE_BEGIN
27
28
29#define _AST_DEF_ACCELERATIONROTATION_PROPERTIES\
30 _AST_DEF_KINEMATICROTATION_PROPERTIES\
31 const Vector3d& rotationRateDot() const { return angvelDot_; }\
32 Vector3d& rotationRateDot() { return angvelDot_; }\
33 const Vector3d& getRotationRateDot() const { return rotationRateDot(); }\
34 Vector3d& getRotationRateDot() { return rotationRateDot(); }\
35 void setRotationRateDot(const Vector3d& angvelDot) { angvelDot_ = angvelDot; }\
36 const AccelerationRotation& accelerationRotation() const { return reinterpret_cast<const AccelerationRotation&>(rotation_); }\
37 AccelerationRotation& accelerationRotation() { return reinterpret_cast<AccelerationRotation&>(rotation_); }\
38 const AccelerationRotation& getAccelerationRotation() const { return accelerationRotation(); }\
39 AccelerationRotation& getAccelerationRotation() { return accelerationRotation(); }\
40 void setAccelerationRotation(const AccelerationRotation& rot) { accelerationRotation() = rot; }\
41
42
51{
52public:
53
56 static AccelerationRotation Identity();
57
60
65 AccelerationRotation(const Matrix3d& mat, const Vector3d& angvel, const Vector3d& angvelDot);
66
71 AccelerationRotation(const Rotation& rot, const Vector3d& angvel, const Vector3d& angvelDot);
72
76 AccelerationRotation(const KinematicRotation& rot, const Vector3d& angvelDot);
77
78 _AST_DEF_ACCELERATIONROTATION_PROPERTIES
79
83 AccelerationRotation& compose(const AccelerationRotation& next);
84
89 AccelerationRotation composed(const AccelerationRotation& next) const;
90
95 AccelerationRotation operator*(const AccelerationRotation& next) const;
96
101 AccelerationRotation& operator*=(const AccelerationRotation& next);
102
105 void getInverse(AccelerationRotation& inversed) const;
106
109 AccelerationRotation inverse() const;
110
122 void transformVecVelAcc(
123 const Vector3d& position,
124 const Vector3d& velocity,
125 const Vector3d& acceleration,
126 Vector3d& positionOut,
127 Vector3d& velocityOut,
128 Vector3d& accelerationOut) const;
129
138 void transformVecVelAccInv(
139 const Vector3d& position,
140 const Vector3d& velocity,
141 const Vector3d& acceleration,
142 Vector3d& positionOut,
143 Vector3d& velocityOut,
144 Vector3d& accelerationOut) const;
145protected:
146 Rotation rotation_{};
147 Vector3d angvel_{};
148 Vector3d angvelDot_{};
149};
150
151A_ALWAYS_INLINE AccelerationRotation AccelerationRotation::Identity()
152{
153 return AccelerationRotation(Matrix3d::Identity(), Vector3d::Zero(), Vector3d::Zero());
154}
155
156A_ALWAYS_INLINE AccelerationRotation::AccelerationRotation(const Matrix3d &mat, const Vector3d &angvel, const Vector3d &angvelDot)
157 : rotation_(mat)
158 , angvel_(angvel)
159 , angvelDot_(angvelDot)
160{
161}
162
163A_ALWAYS_INLINE AccelerationRotation::AccelerationRotation(const Rotation &rot, const Vector3d &angvel, const Vector3d &angvelDot)
164 : rotation_(rot)
165 , angvel_(angvel)
166 , angvelDot_(angvelDot)
167{
168}
169
170A_ALWAYS_INLINE AccelerationRotation::AccelerationRotation(const KinematicRotation &rot, const Vector3d &angvelDot)
171 : rotation_(rot.rotation())
172 , angvel_(rot.rotationRate())
173 , angvelDot_(angvelDot)
174{
175}
176
178{
185 Matrix3d mat1 = this->matrix();
186 Vector3d angvel1 = this->angvel_;
187 Vector3d angvel2InSource = next.angvel_ * mat1; // 即 M1ᵀ ω2
188 Vector3d angvel = angvel1 + angvel2InSource;
189 Vector3d angvelDot = this->angvelDot_ + angvel1.cross(angvel2InSource) + next.angvelDot_ * mat1;
190 return AccelerationRotation(next.matrix() * mat1, angvel, angvelDot);
191}
192
194{
195 *this = this->composed(next);
196 return *this;
197}
198
200{
201 return composed(next);
202}
203
205{
206 return compose(next);
207}
208
209A_ALWAYS_INLINE void AccelerationRotation::getInverse(AccelerationRotation &inversed) const
210{
211 // 先取出matrix_,允许inversed与*this为同一对象
212 Matrix3d mat = this->matrix();
213 Vector3d angvel = this->angvel_;
214 Vector3d angvelDot = this->angvelDot_;
215 inversed.matrix() = mat.transpose();
216 inversed.angvel_ = -(mat * angvel);
217 inversed.angvelDot_ = -(mat * angvelDot); // ω×ω = 0,故角加速度没有附加项
218}
219
221{
223 this->getInverse(retval);
224 return retval;
225}
226
228 const Vector3d &position, const Vector3d &velocity, const Vector3d &acceleration,
229 Vector3d &positionOut, Vector3d &velocityOut, Vector3d &accelerationOut) const
230{
231 // 注意:这里要先计算accelerationOut,再计算velocityOut,最后计算positionOut,
232 // 防止入参与出参地址相同时值被覆盖
233 accelerationOut = this->matrix() * (acceleration
234 - this->angvel_.cross(velocity) * 2.0
235 - this->angvelDot_.cross(position)
236 + this->angvel_.cross(this->angvel_.cross(position)));
237 velocityOut = this->matrix() * (velocity - this->angvel_.cross(position));
238 positionOut = this->matrix() * position;
239}
240
242 const Vector3d &position, const Vector3d &velocity, const Vector3d &acceleration,
243 Vector3d &positionOut, Vector3d &velocityOut, Vector3d &accelerationOut) const
244{
245 // 注意:这里要先计算positionOut,再计算velocityOut,最后计算accelerationOut
246 positionOut = position * this->matrix();
247 velocityOut = velocity * this->matrix() + this->angvel_.cross(positionOut);
248 accelerationOut = acceleration * this->matrix()
249 + this->angvelDot_.cross(positionOut)
250 + this->angvel_.cross(velocityOut) * 2.0
251 - this->angvel_.cross(this->angvel_.cross(positionOut));
252}
253
254AST_NAMESPACE_END
加速度(二阶运动学)坐标系旋转
定义 AccelerationRotation.hpp:51
AccelerationRotation & operator*=(const AccelerationRotation &next)
组合下一个坐标系旋转
定义 AccelerationRotation.hpp:204
void transformVecVelAcc(const Vector3d &position, const Vector3d &velocity, const Vector3d &acceleration, Vector3d &positionOut, Vector3d &velocityOut, Vector3d &accelerationOut) const
变换位置、速度和加速度
定义 AccelerationRotation.hpp:227
AccelerationRotation operator*(const AccelerationRotation &next) const
组合下一个坐标系旋转
定义 AccelerationRotation.hpp:199
Vector3d angvel_
角速度
定义 AccelerationRotation.hpp:147
void getInverse(AccelerationRotation &inversed) const
获取逆旋转
定义 AccelerationRotation.hpp:209
AccelerationRotation composed(const AccelerationRotation &next) const
组合下一个坐标系旋转
定义 AccelerationRotation.hpp:177
void transformVecVelAccInv(const Vector3d &position, const Vector3d &velocity, const Vector3d &acceleration, Vector3d &positionOut, Vector3d &velocityOut, Vector3d &accelerationOut) const
变换位置、速度和加速度(逆变换)
定义 AccelerationRotation.hpp:241
AccelerationRotation()=default
加速度旋转默认构造函数
Vector3d angvelDot_
角加速度
定义 AccelerationRotation.hpp:148
_AST_DEF_ACCELERATIONROTATION_PROPERTIES AccelerationRotation & compose(const AccelerationRotation &next)
组合下一个坐标系旋转
定义 AccelerationRotation.hpp:193
AccelerationRotation inverse() const
获取逆旋转
定义 AccelerationRotation.hpp:220
运动学坐标系旋转
定义 KinematicRotation.hpp:50
坐标系旋转类
定义 Rotation.hpp:55