-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfree.m
executable file
·81 lines (58 loc) · 2.49 KB
/
free.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
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
function [x_positions, y_positions, velocities, accelerations, time, omegas, alphas] = free(velocity, time, position, xStopperLoc, yStopperLoc, bottom)
n = 1;
global GRAVITY DELTA_TIME KINETIC_FRICTION MASS BALLRADIUS INERTIA MOVING_RIGHT MOVING_LEFT PLOT_TIME
elasped_time = 0;
while position(1) < xStopperLoc && position(2) < yStopperLoc
position = velocity * DELTA_TIME + position; + (1/2)*GRAVITY*[0,1]*DELTA_TIME^2;
x(n) = position(1);
y(n) = position(2);
all_velocities(n) = norm(velocity);
all_accelerations(n) = GRAVITY;
velocity = velocity + GRAVITY * DELTA_TIME * [0, 1];
n = n +1;
elasped_time = elasped_time + DELTA_TIME;
end
% WANT IMPULSE HERE. BUT IM ASSUMING ENERGY IS CONSERVED
energy_remain = 1;
velocity = ((energy_remain*norm(velocity)^2)^0.5);
velocity = velocity * [0, -1];
while position(2) > bottom
position = velocity * DELTA_TIME + position + (1/2)*GRAVITY*[0,1]*DELTA_TIME^2;
x(n) = position(1);
y(n) = position(2);
all_velocities(n) = norm(velocity);
all_accelerations(n) = GRAVITY;
velocity = velocity + GRAVITY * DELTA_TIME * [0, 1];
n = n +1;
elasped_time = elasped_time + DELTA_TIME;
end
%
%
time = time + elasped_time;
numOfPoints = floor(elasped_time/PLOT_TIME);
increment = floor(length(all_velocities) / numOfPoints);
velocities = 1:numOfPoints;
accelerations = 1:numOfPoints;
x_positions = 1:numOfPoints;
y_positions = 1:numOfPoints;
omegas = 1:numOfPoints;
alphas = 1:numOfPoints;
% always include initial value.
% Would we wanna always include final value?
velocities(1) = all_velocities(1);
accelerations(1) = all_accelerations(1);
x_positions(1) = x(1);
y_positions(1) = y(1);
for idx = 1:(numOfPoints)
velocities(idx) = all_velocities(idx*increment);
accelerations(idx) = all_accelerations(idx*increment);
x_positions(idx) = x(idx*increment);
y_positions(idx) = y(idx*increment);
omegas(idx) = 0;
alphas(idx) = 0;
end
velocities(length(velocities)) = all_velocities(length(all_velocities));
accelerations(length(velocities)) = all_accelerations(length(all_accelerations));
x_positions(length(velocities) + 1) = x(length(x));
y_positions(length(velocities) + 1) = y(length(y));
end