-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeometry.m
122 lines (105 loc) · 3.78 KB
/
geometry.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
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
classdef geometry
properties
obstacles
segments
n_o % number of obstacles
n_s % number of segments
tags % 1=obstacle,2=segment
n_parts
top_seg
bottom_seg
end
methods
%-------------------------------------------------------------------------%
function obj = cctor(obj,n_o,o_type,n_s,s_type)
if nargin==3
s_type = 'line_segment';
end
obj.n_o = n_o;
obj.n_s = n_s;
obj.n_parts = n_o+n_s;
obj.tags= ones(obj.n_parts,2);
if n_o>0
b(1,n_o) = eval(o_type);
obj.obstacles =b;
obj.tags(1:n_o,2) = (1:n_o)';
end
if n_s>0
s(1,n_s) = eval(s_type);
obj.segments =s;
obj.tags(n_o+1:n_o+n_s,1) = 2*obj.tags(n_o+1:n_o+n_s,1);
obj.tags(n_o+1:n_o+n_s,2) = (1:n_s)';
end
end
%-------------------------------------------------------------------------%
function N = get_N_total(obj)
N = 0;
if obj.n_o>0
for i=1:obj.n_o
N=N + 2*obj.obstacles(i).N;
end
end
if obj.n_s>0
for i=1:obj.n_s
N=N + 2*obj.segments(i).N-1;
end
end
end
%-------------------------------------------------------------------------%
function prt = get_part(obj,t)
% this function gets the t part of the geometry
l = obj.tags(t,2);
if obj.tags(t,1) == 1 % it's an obstacle
prt = obj.obstacles(l);
elseif obj.tags(t,1) ==2 % it's a line segment
prt = obj.segments(l);
end
end
%-------------------------------------------------------------------------%
function Np = get_Np(obj,t)
% this function computes the number of points on the t part of
% the geometry
l = obj.tags(t,2);
if obj.tags(t,1) == 1 % it's an obstacleßß
Np = obj.obstacles(l).Np;
elseif obj.tags(t,1) ==2 % it's a line segment
Np = obj.segments(l).Np;
end
end
%-------------------------------------------------------------------------%
function t_indices = get_indices(obj,t)
% this function computes the indices of the points of the t
% part of the goemetry
n0 = 0;
for p=1:t-1
n0 = n0 + get_Np(obj,p);
end
ni = n0 + 1;
ne = n0 + get_Np(obj,t);
t_indices = (ni:ne)';
end
%-------------------------------------------------------------------------%
function win = get_window(obj)
win = [];
for t = 1:obj.n_parts
prt = obj.get_part(t);
win = [win;prt.win];
end
end
%-------------------------------------------------------------------------%
function plot(obj,nfig)
figure(nfig); hold on
for t = 1:obj.n_parts
prt = obj.get_part(t);
if strcmp(prt.name,'obstacle')
plot([prt.x(:,1);prt.x(1,1)],[prt.x(:,2);prt.x(1,2)]);
else
plot(prt.x(:,1),prt.x(:,2));
end
end
axis equal
axis tight
end
%-------------------------------------------------------------------------%
end
end