-
Notifications
You must be signed in to change notification settings - Fork 67
/
body_centred_body_direction_dynamic_frame_body.hpp
187 lines (167 loc) · 8.04 KB
/
body_centred_body_direction_dynamic_frame_body.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#pragma once
#include "physics/body_centred_body_direction_dynamic_frame.hpp"
#include "geometry/named_quantities.hpp"
#include "geometry/r3x3_matrix.hpp"
#include "quantities/quantities.hpp"
#include "quantities/si.hpp"
namespace principia {
namespace physics {
namespace internal_body_centred_body_direction_dynamic_frame {
using geometry::Bivector;
using geometry::Displacement;
using geometry::R3x3Matrix;
using geometry::Velocity;
using geometry::Wedge;
using quantities::GravitationalParameter;
using quantities::Length;
using quantities::Pow;
using quantities::Product;
using quantities::Speed;
using quantities::Variation;
using quantities::si::Radian;
template<typename InertialFrame, typename ThisFrame>
BodyCentredBodyDirectionDynamicFrame<InertialFrame, ThisFrame>::
BodyCentredBodyDirectionDynamicFrame(
not_null<Ephemeris<InertialFrame> const*> const ephemeris,
not_null<MassiveBody const*> const primary,
not_null<MassiveBody const*> const secondary)
: ephemeris_(ephemeris),
primary_(primary),
secondary_(secondary),
compute_gravitational_acceleration_on_primary_(
[this](Position<InertialFrame> const& position, Instant const& t) {
return ephemeris_->ComputeGravitationalAccelerationOnMassiveBody(
primary_, t);
}),
primary_trajectory_(
[&t = *ephemeris_->trajectory(primary_)]() -> auto& { return t; }),
secondary_trajectory_(ephemeris_->trajectory(secondary_)) {}
template<typename InertialFrame, typename ThisFrame>
BodyCentredBodyDirectionDynamicFrame<InertialFrame, ThisFrame>::
BodyCentredBodyDirectionDynamicFrame(
not_null<Ephemeris<InertialFrame> const*> const ephemeris,
std::function<Trajectory<InertialFrame> const&()> const
primary_trajectory,
not_null<MassiveBody const*> const secondary)
: ephemeris_(ephemeris),
primary_(nullptr),
secondary_(secondary),
compute_gravitational_acceleration_on_primary_(
[this](Position<InertialFrame> const& position, Instant const& t) {
return ephemeris_->ComputeGravitationalAccelerationOnMasslessBody(
position, t);
}),
primary_trajectory_(primary_trajectory),
secondary_trajectory_(ephemeris_->trajectory(secondary_)) {}
template<typename InertialFrame, typename ThisFrame>
RigidMotion<InertialFrame, ThisFrame>
BodyCentredBodyDirectionDynamicFrame<InertialFrame, ThisFrame>::
ToThisFrameAtTime(Instant const& t) const {
DegreesOfFreedom<InertialFrame> const primary_degrees_of_freedom =
primary_trajectory_().EvaluateDegreesOfFreedom(t);
DegreesOfFreedom<InertialFrame> const secondary_degrees_of_freedom =
secondary_trajectory_->EvaluateDegreesOfFreedom(t);
Rotation<InertialFrame, ThisFrame> rotation =
Rotation<InertialFrame, ThisFrame>::Identity();
AngularVelocity<InertialFrame> angular_velocity;
ComputeAngularDegreesOfFreedom(primary_degrees_of_freedom,
secondary_degrees_of_freedom,
rotation,
angular_velocity);
RigidTransformation<InertialFrame, ThisFrame> const
rigid_transformation(primary_degrees_of_freedom.position(),
ThisFrame::origin,
rotation.Forget());
return RigidMotion<InertialFrame, ThisFrame>(
rigid_transformation,
angular_velocity,
primary_degrees_of_freedom.velocity());
}
template<typename InertialFrame, typename ThisFrame>
void BodyCentredBodyDirectionDynamicFrame<InertialFrame, ThisFrame>::
WriteToMessage(not_null<serialization::DynamicFrame*> const message) const {
auto* const extension =
message->MutableExtension(
serialization::BodyCentredBodyDirectionDynamicFrame::extension);
extension->set_primary(ephemeris_->serialization_index_for_body(primary_));
extension->set_secondary(
ephemeris_->serialization_index_for_body(secondary_));
}
template<typename InertialFrame, typename ThisFrame>
not_null<std::unique_ptr<
BodyCentredBodyDirectionDynamicFrame<InertialFrame, ThisFrame>>>
BodyCentredBodyDirectionDynamicFrame<InertialFrame, ThisFrame>::ReadFromMessage(
not_null<Ephemeris<InertialFrame> const*> const ephemeris,
serialization::BodyCentredBodyDirectionDynamicFrame const & message) {
return std::make_unique<BodyCentredBodyDirectionDynamicFrame>(
ephemeris,
ephemeris->body_for_serialization_index(message.primary()),
ephemeris->body_for_serialization_index(message.secondary()));
}
template<typename InertialFrame, typename ThisFrame>
Vector<Acceleration, InertialFrame>
BodyCentredBodyDirectionDynamicFrame<InertialFrame, ThisFrame>::
GravitationalAcceleration(Instant const& t,
Position<InertialFrame> const& q) const {
return ephemeris_->ComputeGravitationalAccelerationOnMasslessBody(q, t);
}
template<typename InertialFrame, typename ThisFrame>
AcceleratedRigidMotion<InertialFrame, ThisFrame>
BodyCentredBodyDirectionDynamicFrame<InertialFrame, ThisFrame>::
MotionOfThisFrame(Instant const& t) const {
DegreesOfFreedom<InertialFrame> const primary_degrees_of_freedom =
primary_trajectory_().EvaluateDegreesOfFreedom(t);
DegreesOfFreedom<InertialFrame> const secondary_degrees_of_freedom =
secondary_trajectory_->EvaluateDegreesOfFreedom(t);
// TODO(egg): eventually we want to add the intrinsic acceleration here.
Vector<Acceleration, InertialFrame> const primary_acceleration =
compute_gravitational_acceleration_on_primary_(
primary_degrees_of_freedom.position(), t);
Vector<Acceleration, InertialFrame> const secondary_acceleration =
ephemeris_->ComputeGravitationalAccelerationOnMassiveBody(secondary_, t);
auto const to_this_frame = ToThisFrameAtTime(t);
// TODO(egg): TeX and reference.
RelativeDegreesOfFreedom<InertialFrame> const secondary_primary =
secondary_degrees_of_freedom - primary_degrees_of_freedom;
Displacement<InertialFrame> const& r = secondary_primary.displacement();
Velocity<InertialFrame> const& ṙ = secondary_primary.velocity();
Vector<Acceleration, InertialFrame> const r̈ =
secondary_acceleration - primary_acceleration;
AngularVelocity<InertialFrame> const& ω =
to_this_frame.angular_velocity_of_to_frame();
Variation<AngularVelocity<InertialFrame>> const
angular_acceleration_of_to_frame =
(Wedge(r, r̈) * Radian - 2 * ω * InnerProduct(r, ṙ)) /
InnerProduct(r, r);
Vector<Acceleration, InertialFrame> const& acceleration_of_to_frame_origin =
primary_acceleration;
return AcceleratedRigidMotion<InertialFrame, ThisFrame>(
to_this_frame,
angular_acceleration_of_to_frame,
acceleration_of_to_frame_origin);
}
template<typename InertialFrame, typename ThisFrame>
void BodyCentredBodyDirectionDynamicFrame<InertialFrame, ThisFrame>::
ComputeAngularDegreesOfFreedom(
DegreesOfFreedom<InertialFrame> const& primary_degrees_of_freedom,
DegreesOfFreedom<InertialFrame> const& secondary_degrees_of_freedom,
Rotation<InertialFrame, ThisFrame>& rotation,
AngularVelocity<InertialFrame>& angular_velocity) {
RelativeDegreesOfFreedom<InertialFrame> const reference =
secondary_degrees_of_freedom - primary_degrees_of_freedom;
Displacement<InertialFrame> const& reference_direction =
reference.displacement();
Velocity<InertialFrame> const reference_normal =
reference.velocity().OrthogonalizationAgainst(reference_direction);
Bivector<Product<Length, Speed>, InertialFrame> const reference_binormal =
Wedge(reference_direction, reference_normal);
rotation = Rotation<InertialFrame, ThisFrame>(Normalize(reference_direction),
Normalize(reference_normal),
Normalize(reference_binormal));
angular_velocity = reference_binormal * Radian /
InnerProduct(reference_direction, reference_direction);
}
} // namespace internal_body_centred_body_direction_dynamic_frame
} // namespace physics
} // namespace principia