-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcontainsPoint.m
75 lines (61 loc) · 1.41 KB
/
containsPoint.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
function res = containsPoint(Z,p)
% containsPoint - determines if the point p is inside the logical zonotope Z1
%
% Syntax:
% res = containsPoint(Z,p)
%
% Inputs:
% Z - zonotope object
% p - point specified as a vector
%
% Outputs:
% res - boolean whether the point is inside the zonotope or not
%
% Example:
% Z = zonotope([1;0],[1 0; 0 1]);
% p = [1;0];
% res = containsPoint(Z,p);
%
%
% Other m-files required: none
% Subfunctions: none
% MAT-files required: none
%
% See also: ---
% Author: Amr Alanwar
% Written: 16-October-2022
% Last update: ---
% Last revision:---
%------------- BEGIN CODE --------------
% parse input arguments
points = [];
if ~isempty(Z.G)
numOfgen = length( Z.G );
L=2^numOfgen;
%T = zeros(L,N);
for i=1:L
table = de2bi(i-1,numOfgen,'left-msb');
onePoint=[ table(1,1)&Z.G{1}];
for j=2:numOfgen
onePoint =xor( onePoint, (table(1,j)&Z.G{j}) );
end
if ~isempty(Z.c)
points = [ points xor(Z.c,onePoint)];
else
points = [ points onePoint];
end
if ismember(p',points','rows')
res = true;
return;
end
end
else
points = Z.c;
end
points=unique(points','rows')';
if ismember(p',points','rows')
res = true;
else
res = false;
end
%------------- END OF CODE --------------