-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstep.m
More file actions
35 lines (28 loc) · 956 Bytes
/
step.m
File metadata and controls
35 lines (28 loc) · 956 Bytes
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
% one time step
% update center of mass velocity
total_force = sum(force, 1) + GRAVITY * N_POINTS;
CM_linear_v = CM_linear_v + total_force / N_POINTS * delta_t;
% update center of mass position
CM_position = CM_position + CM_linear_v * delta_t;
% update angular momentum (L)
total_troque = sum(cross(force, X));
L = L + total_troque * delta_t;
% angular velocity
angular_v = I \ L';
angular_v_cross = [
0 -angular_v(3) angular_v(2);
angular_v(3) 0 -angular_v(1);
-angular_v(2) angular_v(1) 0 ;
];
% R
norm_angular_v = norm(angular_v);
if norm_angular_v ~= 0
projection_matrix = angular_v * angular_v' / norm_angular_v ^ 2;
delta_orientation = norm_angular_v * delta_t;
R = projection_matrix ...
+ cos(delta_orientation) * (eye(3) - projection_matrix) ...
+ sin(delta_orientation) * angular_v_cross / norm_angular_v;
% angular update X
X = X * R;
end
computeForce();