-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pedestrian.m
72 lines (68 loc) · 2.14 KB
/
Pedestrian.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
classdef Pedestrian < handle
properties
x, y, x_old, y_old, h, r, w, l, vx, vy;
end
methods
% Constructor
% Initializes the Pedestrian parameters
function obj = Pedestrian(W, L)
obj.w = W;
obj.l = L;
obj.x = RandomIn(1, W);
obj.y = RandomIn(1, L);
obj.x_old = obj.x;
obj.y_old = obj.y;
obj.h = normrnd(1.70, 0.10);
obj.r = normrnd(1.0, 0.1);
obj.vx = RandomIn(-2, 2);
obj.vy = RandomIn(-2, 2);
end
% Walk Method
% Updated Pedestrian position, gives the pedestrian a new random
% velocity and takes care of boundaries
function obj = Walk(obj)
% compute new position
dx = obj.vx;
dy = obj.vy;
X = obj.x + dx;
Y = obj.y + dy;
% check if pedestrian goes out of the left or right border
if (X<1)
X=obj.w;
end
if(X>obj.w)
X=1;
end
% check if pedestrian goes out of upper and lower border
if(Y<1)
Y=obj.l;
end
if(Y>obj.l)
Y=1;
end
% update pedestrian position
obj.x_old = obj.x;
obj.y_old = obj.y;
obj.x = X;
obj.y = Y;
% update pedestrian velocity
dvx = RandomIn(-2, 2);
dvy = RandomIn(-2, 2);
obj.vx = obj.vx + dvx;
obj.vy = obj.vy + dvy;
end
% GoBack Method
% Moves back the pedestrian to his previous location
% and gives him a random velocity
function obj = GoBack(obj)
% compute new position
obj.x = obj.x_old;
obj.y = obj.y_old;
% update pedestrian velocity
dvx = RandomIn(-2, 2);
dvy = RandomIn(-2, 2);
obj.vx = obj.vx + dvx;
obj.vy = obj.vy + dvy;
end
end
end