-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathplot.m
86 lines (74 loc) · 2.17 KB
/
plot.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
function han = plot(Z,varargin)
% plot - Plots 2-dimensional projection of a zonotope
%
% Syntax:
% h = plot(Z) plots the zonotope Z for the first two dimensions
% h = plot(Z,dims) plots the zonotope Z for the two dimensions i,j:
% "dims=[i,j]" and returns handle to line-plot object
% h = plot(Z,dims,'Color','red',...) adds the standard plotting preferences
%
% Inputs:
% Z - zonotope object
% dims - (optional) dimensions that should be projected
% type - (optional) plot settings (LineSpec and name-value pairs)
%
% Outputs:
% han - handle of graphics object
%
% Example:
% Z=zonotope([1 1 0; 0 0 1]);
% plot(Z)
%
% Other m-files required: none
% Subfunctions: none
% MAT-files required: none
%
% See also: polygon
% Author: Matthias Althoff
% Written: 27-July-2016
% Last update: 14-July-2020 (merge with plotFilled)
% Last revision:---
%------------- BEGIN CODE --------------
% default values
dims = [1,2];
linespec = 'b*';
filled = false;
height = [];
NVpairs = {};
cont =0;
%If two arguments are passed
if nargin==2
dims=varargin{1};
%If three or more arguments are passed
elseif nargin>=3
dims = varargin{1};
% parse plot options
[linespec,NVpairs] = readPlotOptions(varargin(2:end));
[NVpairs,filled] = readNameValuePair(NVpairs,'Filled','islogical');
[NVpairs,cont] = readNameValuePair(NVpairs,'Cont','islogical');
[NVpairs,height] = readNameValuePair(NVpairs,'Height','isscalar');
end
% project zonotope
Z = project(Z,dims);
% convert zonotope to polygon
p = evaluate(Z);
%plot and output the handle
if filled
if isempty(height) % no 3D plot
han = fill(p(1,:),p(2,:),linespec,NVpairs{:});
else
zCoordinates = height*ones(length(p(1,:)),1);
han = fill3(p(1,:),p(2,:),zCoordinates,linespec,NVpairs{:});
end
elseif cont
poly=mptPolytope.enclosePoints(p);
plot(poly,dims,linespec);
else
if isempty(height) % no 3D plot
han = plot(p(1,:),p(2,:),linespec,NVpairs{:});
else
zCoordinates = height*ones(length(p(1,:)),1);
han = plot3(p(1,:),p(2,:),zCoordinates,linespec,NVpairs{:});
end
end
%------------- END OF CODE --------------