-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathaircraftAddBody.m
36 lines (22 loc) · 1010 Bytes
/
aircraftAddBody.m
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
function aircraft = aircraftAddBody(aircraft, component)
% New CoG in c frame
CoG_Pos_c = (aircraft.body.m * aircraft.config.CoG_Pos_c + component.body.m * component.config.CoG_Pos_c)./(aircraft.body.m + component.body.m);
% New total mass
m = aircraft.body.m + component.body.m;
% New inertia at new CoG
pos_offset_aircraft = aircraft.config.CoG_Pos_c - CoG_Pos_c;
I_aircraft = inertiaWithOffset(pos_offset_aircraft, aircraft.body.I, aircraft.body.m);
pos_offset_component = component.config.CoG_Pos_c - CoG_Pos_c;
I_component = inertiaWithOffset(pos_offset_component, component.body.I, component.body.m);
aircraft.config.CoG_Pos_c = CoG_Pos_c;
aircraft.body.m = m;
aircraft.body.I = I_aircraft + I_component;
end
%% LOCAL FUNCTIONS
function I = inertiaWithOffset(pos_offset, I_CoG, m)
% ToDo: Implement rotation!
a = [ 0, -pos_offset(3), pos_offset(2)
pos_offset(3), 0, -pos_offset(1)
-pos_offset(2), pos_offset(1), 0 ];
I = I_CoG + m * (a' * a);
end