/usr/share/octave/packages/interval-2.1.0/@infsup/plot3.m is in octave-interval 2.1.0-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 | ## Copyright 2015-2016 Oliver Heimlich
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, see <http://www.gnu.org/licenses/>.
## -*- texinfo -*-
## @documentencoding UTF-8
## @defmethod {@@infsup} plot3 (@var{X}, @var{Y}, @var{Z})
## @defmethodx {@@infsup} plot3 (@var{X}, @var{Y}, @var{Z}, @var{COLOR})
## @defmethodx {@@infsup} plot3 (@var{X}, @var{Y}, @var{Z}, @var{COLOR}, @var{EDGECOLOR})
##
## Create a 3D-plot of intervals.
##
## If either of @var{X}, @var{Y} or @var{Z} is an empty interval, nothing is
## plotted. If all are singleton intervals, a single point is plotted. If
## two intervals are a singleton interval, a line is plotted. If one interval
## is a singleton interval, a rectangle is plotted. If neither of @var{X},
## @var{Y} and @var{Z} is a singleton interval, a cuboid is plotted.
##
## When interval matrices of equal size are given, each triple of elements is
## printed separately.
##
## No connection of the interval areas is plotted, because that kind of
## interpolation would be wrong in general (in the sense that the actual values
## are enclosed by the plot).
##
## If no @var{COLOR} is given, the current @command{colormap} is used. Use
## @var{COLOR} = @option{none} to disable plotting of filled rectangles. If an
## optional parameter @var{EDGECOLOR} is given, rectangles and cuboids will
## have visible edges in a distinct color.
##
## @end defmethod
## Author: Oliver Heimlich
## Keywords: interval
## Created: 2015-05-17
function plot3 (x, y, z, color, edgecolor)
if (nargin < 3 || nargin > 5)
print_usage ();
return
endif
warning ("off", "interval:ImplicitPromote", "local");
if (not (isa (x, "infsupdec")))
x = infsupdec (x);
endif
if (not (isa (y, "infsupdec")))
y = infsupdec (y);
endif
if (not (isa (z, "infsupdec")))
z = infsupdec (z);
endif
if (nargin < 4 || isempty (color))
color = 'interp';
if (nargin < 5)
# will only be used for lines and dots
edgecolor = colormap ()(1, :);
endif
elseif (nargin < 5)
# will only be used for lines and dots
edgecolor = color;
endif
oldhold = ishold ();
if (not (oldhold))
clf
hold on
endif
pointsize = 3;
edgewidth = 2;
unwind_protect
empty = isempty (x) | isempty (y) | isempty (z);
number_of_singletons = issingleton (x) + issingleton (y) + issingleton (z);
points = number_of_singletons == 3;
lines = number_of_singletons == 2 & not (empty);
boxes = number_of_singletons <= 1 & not (empty);
if (any (points(:)))
scatter3 (x.inf(points), y.inf(points), z.inf(points), ...
pointsize, ...
edgecolor, ...
'filled');
endif
if (any (lines(:)))
x_line = [vec(x.inf(lines)), vec(x.sup(lines))]';
y_line = [vec(y.inf(lines)), vec(y.sup(lines))]';
z_line = [vec(z.inf(lines)), vec(z.sup(lines))]';
line (x_line, y_line, z_line, ...
'linewidth', edgewidth, ...
'color', edgecolor);
endif
## + z
## |
##
## B--------D
## /| /|
## / | / |
## / A-----/--C -+
## F--------H / y
## | / | /
## |/ |/
## E--------G
##
## /
## + x
## The variables A through H help indexing the relevant rows in vertices.
[A, B, C, D, E, F, G, H] = num2cell ((0 : 7) * sum (sum (boxes))) {:};
vertices = [vec(x.inf(boxes)), vec(y.inf(boxes)), vec(z.inf(boxes)); ...
vec(x.inf(boxes)), vec(y.inf(boxes)), vec(z.sup(boxes)); ...
vec(x.inf(boxes)), vec(y.sup(boxes)), vec(z.inf(boxes)); ...
vec(x.inf(boxes)), vec(y.sup(boxes)), vec(z.sup(boxes)); ...
vec(x.sup(boxes)), vec(y.inf(boxes)), vec(z.inf(boxes)); ...
vec(x.sup(boxes)), vec(y.inf(boxes)), vec(z.sup(boxes)); ...
vec(x.sup(boxes)), vec(y.sup(boxes)), vec(z.inf(boxes)); ...
vec(x.sup(boxes)), vec(y.sup(boxes)), vec(z.sup(boxes))];
if (any (boxes(:)))
## To support gnuplot as a plotting backend, we have to use
## triangular instead of rectangular patches (see bug #45594).
faces = zeros (0, 3);
## x-y rectangle at z.inf
select = vec (find (x.inf(boxes) < x.sup(boxes) & ...
y.inf(boxes) < y.sup(boxes)));
faces = [faces; ...
A+select, C+select, G+select; ...
G+select, E+select, A+select];
## x-z rectangle at y.inf
select = vec (find (x.inf(boxes) < x.sup(boxes) & ...
z.inf(boxes) < z.sup(boxes)));
faces = [faces; ...
A+select, E+select, F+select; ...
F+select, B+select, A+select];
## y-z rectangle at x.inf
select = vec (find (y.inf(boxes) < y.sup(boxes) & ...
z.inf(boxes) < z.sup(boxes)));
faces = [faces; ...
A+select, B+select, D+select; ...
D+select, C+select, A+select];
## The cuboids have 6 sides instead of only one
select = vec (find (x.inf(boxes) < x.sup(boxes) & ...
y.inf(boxes) < y.sup(boxes) & ...
z.inf(boxes) < z.sup(boxes)));
faces = [faces; ...
## x-y rectangle at z.sup
B+select, F+select, H+select; ...
H+select, D+select, B+select; ...
## x-z rectangle at y.sup
C+select, D+select, H+select;
H+select, G+select, C+select; ...
## y-z rectangle at x.inf
E+select, G+select, H+select; ...
H+select, F+select, E+select];
patch ('Vertices', vertices, ...
'Faces', faces, ...
'EdgeColor', 'none', ...
'FaceColor', color, ...
'FaceVertexCData', vertices (:, 3));
## Draw edges for the rectangles.
##
## B B--------D D
## /| | | /|
## / | | | / |
## / A A--------C/ C or A--------C
## F / F--------H H / / /
## | / | | | / / /
## |/ | | |/ / /
## E E--------G G E--------G
##
## Note: The edges A-B, C-D, E-F, and G-H may be drawn twice.
## However, the benefit is that this approach produces only closed
## routes between the points, which is beneficial since it prevents
## graphics artifacts from line endings. Line endings might be rendered
## differently and we want to prevent that.
if (nargin >= 5)
faces = zeros (0, 4);
## x-y rectangle at z.inf
select = vec (find (x.inf(boxes) < x.sup(boxes) & ...
y.inf(boxes) < y.sup(boxes) & ...
z.inf(boxes) == z.sup(boxes)));
faces = [faces; ...
A+select, C+select, G+select, E+select];
## x-z rectangle at y.inf
select = vec (find (x.inf(boxes) < x.sup(boxes) & ...
z.inf(boxes) < z.sup(boxes)));
faces = [faces; ...
A+select, E+select, F+select, B+select];
## y-z rectangle at x.inf
select = vec (find (y.inf(boxes) < y.sup(boxes) & ...
z.inf(boxes) < z.sup(boxes)));
faces = [faces; ...
A+select, B+select, D+select, C+select];
## The cuboids have 6 sides instead of only one.
## It suffices to draw edges for 2 more sides (4 sides in total).
select = vec (find (x.inf(boxes) < x.sup(boxes) & ...
y.inf(boxes) < y.sup(boxes) & ...
z.inf(boxes) < z.sup(boxes)));
faces = [faces; ...
## x-z rectangle at y.sup
C+select, D+select, H+select, G+select; ...
## y-z rectangle at x.inf
E+select, G+select, H+select, F+select];
patch ('Vertices', vertices, ...
'Faces', faces, ...
'EdgeColor', edgecolor, ...
'LineWidth', edgewidth, ...
'FaceColor', 'none');
endif
endif
unwind_protect_cleanup
## Reset hold state and set the viewpoint for 3-D graphs (the latter would
## not happen automatically since above functions operate on 2-D objects).
if (not (oldhold))
hold off
view (3)
endif
end_unwind_protect
endfunction
%!# this test is rather pointless
%!test
%! clf
%! plot3 (empty (), empty (), empty ());
%! close
%!demo
%! clf
%! colormap hot
%! x = y = z = (1 : 3) + infsup ("[0, 1]");
%! plot3 (x, y, z);
%! grid on
%!demo
%! clf
%! colormap jet
%! z = 1 : 8;
%! x = y = infsup ("[-1, 1]") ./ z;
%! plot3 (x, y, z);
%! grid on
%!demo
%! clf
%! [x, y] = meshgrid (mince (infsup ("[-5, 5]"), 20), ...
%! mince (infsup ("[0.1, 5]"), 10));
%! z = log (hypot (x, y));
%! blue = [38 139 210]/255; base2 = [238 232 213]/255;
%! plot3 (x, y, z, base2, blue);
%! view (330, 12)
%!demo
%! clf
%! [x, y] = meshgrid (midrad (-10 : 0.5 : 10, .25));
%! z = sin (hypot (x, y)) .* hypot (x, y);
%! plot3 (mid (x), mid (y), z);
%! grid on
|