1## Copyright (C) 1998-2003 Joao Cardoso.
2##
3## This program is free software; you can redistribute it and/or modify it
4## under the terms of the GNU General Public License as published by the
5## Free Software Foundation; either version 2 of the License, or (at your
6## option) any later version.
7##
8## This program is distributed in the hope that it will be useful, but
9## WITHOUT ANY WARRANTY; without even the implied warranty of
10## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11## General Public License for more details.
12##
13## This file is part of plplot_octave.
14
15## plot3 (x, y, z [, fmt])
16##
17## PLOT3() is a three-dimensional analogue of PLOT().
18##
19## PLOT3(x,y,z), where x, y and z are three vectors of the same length,
20## plots a line in 3-space through the points whose coordinates are the
21## elements of x, y and z.
22##
23## PLOT3(X,Y,Z), where X, Y and Z are three matrices of the same size,
24## plots several lines obtained from the columns of X, Y and Z.
25##
26## Various plot type, symbols and colors may be obtained with
27## PLOT3(X,Y,Z,s) where s is a 1, 2 or 3 character string made from
28## the characters listed under the PLOT command. See __pl_opt() and plot().
29
30function plot3 (x, y, z, fmt)
31
32  global __pl
33  strm = __pl_init;
34
35  if (nargin != 4 & nargin != 3)
36    error("plot3: not yet.\n");
37  endif
38
39  if (isvector(x) & isvector(y) & isvector(y))
40
41    if (nargin == 3)
42      fmt = "-r";
43    endif
44
45    __pl_plot3(x, y, z, fmt);
46
47  elseif (ismatrix(x) & ismatrix(y) & ismatrix(z))
48
49    if (!common_size(x,y,z))
50
51      if (rows(x) < columns(x))
52	x = x'; y = y'; z = z';
53      endif
54
55      if (nargin == 3)
56	fmt = "-r";
57	for i=2:columns(x)
58	  fmt = [fmt; sprintf("%d%d", i, i)];
59	endfor
60      elseif (rows(fmt) == 1)
61	for i=2:columns(x)
62	  fmt = [fmt; fmt];
63	endfor
64      elseif (rows(fmt) != columns(x))
65	error("plot3: `fmt' must have same length as `x'.\n");
66      endif
67
68      xm = min(min(x)); xM = max(max(x));
69      ym = min(min(y)); yM = max(max(y));
70      zm = min(min(z)); zM = max(max(z));
71
72      if (__pl.axis_st(strm))
73	xm = __pl.axis(strm,1); xM = __pl.axis(strm,2);	# at least x always exist
74
75	if (length(__pl.axis) >= 4)
76	  ym = __pl.axis(strm,3); yM = __pl.axis(strm,4);
77	else
78	  __pl.axis(strm,3) = ym; __pl.axis(strm,4) = yM;
79	endif
80	if (length(__pl.axis) == 6)
81	  zm = __pl.axis(strm,5); zM = __pl.axis(strm,6);
82	else
83	  __pl.axis(strm,5) = zm; __pl.axis(strm,6) = zM;
84	endif
85      else	# make axis() return current axis
86	__pl.axis(strm,1) = xm; __pl.axis(strm,2) = xM;
87	__pl.axis(strm,3) = ym; __pl.axis(strm,4) = yM;
88	__pl.axis(strm,5) = zm; __pl.axis(strm,6) = zM;
89      endif
90
91      h_st = ishold;
92
93      if (!ishold)
94	plcol0(15);
95	__pl_plenv(-1.6, 1.6, -1.6, 2.6, 0, -2);
96	pllab("", "", tdeblank(__pl.tlabel(strm,:)));
97	plw3d(2, 2, 2, xm, xM, ym, yM, zm, zM,...
98	      __pl.alt(strm), __pl.az(strm))
99	plbox3("bnstu", tdeblank(__pl.xlabel(strm,:)), 0.0, 0,...
100	       "bnstu",tdeblank(__pl.ylabel(strm,:)), 0.0, 0,...
101	       "bcdmnstuv", tdeblank(__pl.zlabel(strm,:)), 0.0, 0)
102	hold on
103      endif
104
105      for i=1:columns(x)
106	__pl_plot3(x(:,i), y(:,i), z(:,i), fmt(i,:));
107      endfor
108
109      if (h_st == 0)
110	hold off
111      endif
112    else
113      error("plot3: x and y and z must have same dimension\n");
114    endif
115  endif
116
117endfunction
118