1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) 2011 - INRIA - Serge Steer <serge.steer@inria.fr>
3 // Copyright (C) 2012 - 2016 - Scilab Enterprises
4 // Copyright (C) 2018 - 2019 - Samuel GOUGEON
6 // This file is hereby licensed under the terms of the GNU GPL v2.0,
7 // pursuant to article 5.3.4 of the CeCILL v.2.1.
8 // This file was originally licensed under the terms of the CeCILL v2.1,
9 // and continues to be available under such terms.
10 // For more information, see the COPYING file which you should have received
11 // along with this program.
13 function comet3d(varargin)
14 // 3D Comet-like trajectory.
17 // comet3d(x, y, z, Lf) // Lf: Leading fraction
18 // comet3d(x, y, fun) // fun: function identifier, polynomial, rational
19 // comet3d(x, y, fun, Lf)
20 // comet3d(...,"colors", c) // c: -1, 4, "orange", "ma", "#RRGGBB", [r g b]
23 // 2018: colors as "name" "nam" "#RRGGBB" or [r g b] now allowed
26 if nv >= 3 & varargin(nv-1)=="colors" then
27 c = iscolor( varargin(nv))
29 msg = "%s: Argument #%d: Wrong color specification.\n";
30 error(msprintf(msg, "comet", nv))
35 varargin = list(varargin(1:$-2))
43 if or(size(z)==1) then
51 [x,y,z] = varargin(1:3)
54 [x,y,z,p] = varargin(1:4)
56 msg = _("%s: Wrong number of input arguments: %d or %d to %d expected.\n")
57 error(msprintf(msg, "comet3d", 1, 3, 6))
61 if type(x) <> 1 | ~isreal(x) then
62 msg = _("%s: Wrong type for argument #%d: Real vector expected.\n")
63 error(msprintf(msg, "comet3d", 1))
65 if type(y)<>1|~isreal(x) then
66 msg = _("%s: Wrong type for argument #%d: Real vector expected.\n")
67 error(msprintf(msg, "comet3d", 1))
70 if (type(z)<>1|~isreal(z))&type(z)<>13 then
71 msg = _("%s: Wrong type for argument #%d: Real vector expected.\n")
72 error(msprintf(msg, "comet3d", 3))
80 if n <> size(y,"*") then
81 msg = _("%s: Incompatible input arguments #%d and #%d: Same sizes expected.\n")
82 error(msprintf(msg, "comet3d", 1, 2))
84 prot=funcprot();funcprot(0)
92 if or(size(z)==1) then
99 if or(size(x)==1) then
101 if size(x,"*")<>n then
102 msg = _("%s: Wrong size for argument #%d: %d expected.\n")
103 error(msprintf(msg, "comet3d", 1, n))
107 if or(size(x)<>size(z)) then
108 msg = _("%s: Incompatible input arguments #%d and #%d: Same sizes expected.\n")
109 error(msprintf(msg, "comet3d", 1, 3))
112 if or(size(y)==1) then
114 if size(y,"*")<>n then
115 msg = _("%s: Wrong size for argument #%d: %d expected.\n")
116 error(msprintf(msg, "comet3d", 2, n))
120 if or(size(y)<>size(z)) then
121 msg = _("%s: Incompatible input arguments #%d and #%d: Same sizes expected.\n")
122 error(msprintf(msg, "comet3d", 2, 3))
129 if type(p) <> 1 | ~isreal(p) | size(p,"*") > 1 then
130 msg = _("%s: Wrong type for argument #%d: Real scalar expected.\n")
131 error(msprintf(msg, "comet3d", 3))
134 msg = _("%s: Wrong value for input argument #%d: Must be in the interval %s.\n")
135 error(msprintf(msg, "comet3d", 3, "[0 1["))
141 if size(c,"*") <> m then
142 msg = _("%s: Wrong size for argument #%d: %d expected.\n")
143 error(msprintf(msg, "comet", nv, m))
150 if axes.children==[] then
151 axes.data_bounds = [min(x) min(y) min(z);max(x) max(y) max(z)];
152 axes.axes_visible = "on";
155 axes.data_bounds = [min(axes.data_bounds(1,:), [min(x) min(y) min(z)]);
156 max(axes.data_bounds(2,:), [max(x) max(y) max(z)])];
158 //create the head, body and tail polylines
163 tail(l).foreground = c(l);
167 body(l).foreground = c(l);
168 body(l).thickness = 2;
169 xpoly([], [], "marks");
171 head(l).mark_size_unit = "point";
172 head(l).mark_size = 6;
173 head(l).mark_style = 9;
174 head(l).mark_foreground = c(l);
181 step = ceil(n/200); //used to speed up the drawing
185 head(l).data = [x(i,l),y(i,l),z(i,l)];
187 body(l).data = [body(l).data;[x(i,l),y(i,l),z(i,l)]];
189 body(l).data = [body(l).data(2:$,:);[x(i,l),y(i,l),z(i,l)]];
190 tail(l).data =[ tail(l).data;[x(i-k,l),y(i-k,l),z(i-k,l)]];
193 if modulo(i,step)==0 then
194 fig.immediate_drawing = "on";
195 fig.immediate_drawing = "off";
198 drawnow(),drawlater()
202 body(l).data = body(l).data(2:$,:);
203 tail(l).data = [tail(l).data;[x(i-k,l),y(i-k,l),z(i-k,l)]];
205 if modulo(i,step)==0 then
206 fig.immediate_drawing = "on";
207 fig.immediate_drawing = "off";
213 //not to generate an error message if the window is closed
214 exec(anim, "errcatch", -1)