/usr/share/freemat/toolbox/graph/plot3.m is in freemat-data 4.0-5build1.
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 | % PLOT3 PLOT3 Plot 3D Function
%
% Usage
%
% This is the 3D plot command. The general syntax for its use is
%
% plot3(X,Y,Z,{linespec 1},X,Y,Z,{linespec 2},...,properties...)
%
% where X Y and Z are the coordinates of the points on the
% 3D line. Note that in general, all three should be vectors. If
% some or all of the quantities are matrices, then FreeMat will attempt
% to expand the vector arguments to the same size, and then generate
% multiple plots, one for each column of the matrices. The linespec
% is optional, see plot for details. You can specify properties
% for the generated line plots. You can also specify a handle as an
% axes to target
%
% plot3(handle,...)
%
% Copyright (c) 2002-2006 Samit Basu
% Licensed under the GPL
function hout = plot3(varargin)
% Check for an axes handle
if (nargin>=2)
if (isnumeric(varargin{1}) && (length(varargin{1})==1) && ...
ishandle(varargin{1},'axes'))
handle = varargin{1}(1);
varargin(1) = [];
nargin = nargin - 1;
else
handle = newplot;
end
end
saveca = gca;
axes(handle);
% search for the propertyname/value pairs
propstart = 0;
if (nargin > 2)
propstart = nargin-1;
while ((propstart >= 1) && isa(varargin{propstart},'char') && ...
pvalid('line',varargin{propstart}))
propstart = propstart - 2;
end
propstart = propstart + 2;
end
propset = {};
if ((propstart > 0) && (propstart < nargin))
propset = varargin(propstart:end);
varargin(propstart:end) = [];
end
h = [];
while (~isempty(varargin))
cs = ''; ms = ''; ps = '';
if (length(varargin) < 3)
error('plot3 requires triplets of x, y, z coordinates');
end;
if (length(varargin) == 3 || (length(varargin) > 3) && ~islinespec(varargin{4},cs,ms,ps))
h = [h,plot_triplet(varargin{1},varargin{2},varargin{3},handle,propset)];
varargin(1:3) = [];
elseif ((length(varargin) >= 4) && islinespec(varargin{4},cs,ms,ps))
h = [h,plot_triplet(varargin{1},varargin{2},varargin{3},handle,completeprops(cs,ms,ps,propset))];
varargin(1:4) = [];
end;
end
if ~ishold
view( handle, 3 );
grid;
end
axes(saveca);
if (nargout > 0)
hout = h;
end
function h = plot_triplet(X,Y,Z,handle,lineprops)
h = [];
if ((isvector(X) | isvector(Y) | isvector(Z)) && (~isvector(X) | ~isvector(Y) | ~isvector(Z)))
rows = max([size(X,1),size(Y,1),size(Z,1)]);
cols = max([size(X,2),size(Y,2),size(Z,2)]);
X = expandmat(X,rows,cols);
Y = expandmat(Y,rows,cols);
Z = expandmat(Z,rows,cols);
end
if (isvector(X)), X = X(:); end;
if (isvector(Y)), Y = Y(:); end;
if (isvector(Z)), Z = Z(:); end;
for i=1:size(Z,2)
h = [h,tplotvector(handle,X(:,i),Y(:,i),Z(:,i),lineprops)];
end
function x = expandmat(a,rows,cols)
if (length(b) == rows)
x = repmat(b(:),[1,cols]);
elseif (length(b) == cols)
x = repmat(b(:)',[rows,1]);
else
error('plot3(X,Y,Z) where one or more arguments are vectors requires the other arguments to have a matching dimension');
end
function k = tplotvector(handle,x,y,z,lineprops)
set(handle,'color','w');
ndx = length(get(handle,'children'))+1;
% Get the colororder
colororder = get(handle,'colororder');
% select the row using a modulo
ndxmod = round(mod(ndx-1,size(colororder,1))+1);
k = hline('xdata',x,'ydata',y,'zdata',z,'color',colororder(ndxmod,:),lineprops{:});
|