summaryrefslogtreecommitdiffstats
path: root/scilab/modules
diff options
context:
space:
mode:
authorSerge Steer <serge.steer@scilab.org>2011-04-19 17:28:17 +0200
committerVincent COUVERT <vincent.couvert@scilab.org>2011-05-06 10:47:37 +0200
commit4a1dd79532bcff6a55c474344cbfc486e4570b6b (patch)
treeb6bc7132ad99f84ee84f7ab93689facaa39504af /scilab/modules
parent7e9b83d4b50a6bbdab3fb7b740fd6d968d3140a2 (diff)
downloadscilab-4a1dd79532bcff6a55c474344cbfc486e4570b6b.zip
scilab-4a1dd79532bcff6a55c474344cbfc486e4570b6b.tar.gz
comet and comet3d, Matlab like functions
Change-Id: I6162b1158c41d23273f4f831a86317e53e2ad698
Diffstat (limited to 'scilab/modules')
-rw-r--r--scilab/modules/graphics/help/en_US/2d_plot/comet.xml180
-rw-r--r--scilab/modules/graphics/help/en_US/2d_plot/paramfplot2d.xml44
-rw-r--r--scilab/modules/graphics/help/en_US/3d_plot/comet3d.xml178
-rw-r--r--scilab/modules/graphics/macros/comet.sci173
-rw-r--r--scilab/modules/graphics/macros/comet3d.sci198
5 files changed, 764 insertions, 9 deletions
diff --git a/scilab/modules/graphics/help/en_US/2d_plot/comet.xml b/scilab/modules/graphics/help/en_US/2d_plot/comet.xml
new file mode 100644
index 0000000..75b4335
--- /dev/null
+++ b/scilab/modules/graphics/help/en_US/2d_plot/comet.xml
@@ -0,0 +1,180 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<!--
3 * Add some comments about XML file
4-->
5<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" version="5.0-subset Scilab" xml:lang="en_US" xml:id="comet">
6 <info>
7 <pubdate>$LastChangedDate: 11-03-2011 $</pubdate>
8 </info>
9 <refnamediv>
10 <refname>comet</refname>
11 <refpurpose>2D comet animated plot. </refpurpose>
12 </refnamediv>
13 <refsynopsisdiv>
14 <title>Calling Sequence</title>
15 <synopsis>comet(y)</synopsis>
16 <synopsis>comet(x,y)</synopsis>
17 <synopsis>comet(x,fun)</synopsis>
18 <synopsis>comet(x,y,p)</synopsis>
19 <synopsis>comet(x,fun,p)</synopsis>
20 <synopsis>comet(...,"colors",c)</synopsis>
21 </refsynopsisdiv>
22 <refsection>
23 <title>Parameters</title>
24 <variablelist>
25 <varlistentry>
26 <term>x</term>
27 <listitem>
28 <para>
29 a real vector or matrix. If omitted, it is assumed to be the vector
30 <literal>1:ny</literal> where <literal>ny</literal> is the
31 number of curve points (see below).
32 </para>
33 </listitem>
34 </varlistentry>
35 <varlistentry>
36 <term>y</term>
37 <listitem>
38 <para>
39 a real vector or matrix of length.
40 </para>
41 </listitem>
42 </varlistentry>
43 <varlistentry>
44 <term>p</term>
45 <listitem>
46 <para>
47 a real scalar in the interval<literal>[0 1[</literal>. Default value is 0.1.
48 </para>
49 </listitem>
50 </varlistentry>
51 <varlistentry>
52 <term>fun</term>
53 <listitem>
54 <para>
55 a scilab function with calling sequence <literal>y=fun(x)</literal>. <literal>fun</literal> can also be a polynomial or a rational fraction.
56 </para>
57 </listitem>
58 </varlistentry>
59 <varlistentry>
60 <term>c</term>
61 <listitem>
62 <para>
63 a vector of <literal>ny</literal> color index.
64 </para>
65 </listitem>
66 </varlistentry>
67
68 </variablelist>
69 </refsection>
70 <refsection>
71 <title>Description</title>
72 <para>
73 If <literal>(x,y)</literal> are two vectors with the same number
74 of elements, this function draws a 2D comet animated plot
75 showing the progession of the curve
76 <literal>(x(1:k),y(1:k))</literal> for <literal>k</literal>
77 varying from <literal>1</literal> to
78 <literal>size(x,'*')</literal>.
79 </para>
80 <para>
81 The plot is made of three parts:
82 <variablelist>
83 <varlistentry>
84 <term>a head</term>
85 mark that shows the current <literal>(x(i),y(i))</literal> position.
86 <listitem>
87 <para>
88 </para>
89 </listitem>
90 </varlistentry>
91 <varlistentry>
92 <term>a body</term> that shows the trailing curve that
93 follows the head: the
94 <literal>(x(i-k:i),y(i-k:i)</literal>) part of the curve.
95 <listitem>
96 <para>
97 </para>
98 </listitem>
99 </varlistentry>
100 <varlistentry>
101 <term>a tail</term>
102 that shows the <literal>(x(1:i-k),y(1:i-k))</literal> part of the curve.
103 <listitem>
104 <para>
105 </para>
106 </listitem>
107 </varlistentry>
108 </variablelist>
109 <para>
110 <literal>comet(x,fun,...)</literal> is equivalent to <literal>comet(x,feval(x,fun),...)</literal>
111 </para>
112 <para>
113 <literal>comet(...,p)</literal> can be used to set the
114 relative length of the body. <literal>k</literal> is defined
115 as <literal>k = round(p*ny)</literal>.
116 </para>
117 <para>
118 if <literal>y</literal> is a matrix then animated curves are drawn for each pair <literal>(x,y(:,l))</literal>.
119 in this case <literal>ny</literal> is the number of rows of <literal>y</literal>.
120 </para>
121 <para>
122 if <literal>x</literal> and <literal>y</literal> are
123 matrices with identical sizes then animated curves are drawn
124 for each pair <literal>(x(:,l),y(:,l))</literal>. in this
125 case <literal>ny</literal> is the number of rows of
126 <literal>x</literal>and <literal>y</literal>.
127 </para>
128
129 <para>
130 <literal>comet(...,"colors",c)</literal> can be used to set the colors of each curves.
131 </para>
132
133 </para>
134 </refsection>
135 <refsection>
136 <title>Examples</title>
137 <programlisting role="example"><![CDATA[
138t = linspace(0,10*%pi,500);
139clf();set(gca(),"isoview","on"); //set isoview axes
140comet(t.*sin(t),t.*cos(t))
141 ]]></programlisting>
142 <programlisting role="example"><![CDATA[
143t = linspace(0,10*%pi,500)';
144clf();comet(t.*sin(t),[t.*sin(2*t) t.*sin(3*t)])
145 ]]></programlisting>
146 <programlisting role="example"><![CDATA[
147function y=traj(x),y=1.5*sin(x^2),endfunction
148clf();comet(linspace(0,5,500),traj)
149 ]]></programlisting>
150 <programlisting role="example"><![CDATA[
151clf();comet(linspace(-2,4,500),(%s-3)/(%s^3+2*%s^2+1))
152 ]]></programlisting>
153
154 </refsection>
155 <refsection>
156 <title>See Also</title>
157 <simplelist type="inline">
158 <member>
159 <link linkend="comet3d">comet3d</link>
160 </member>
161 <member>
162 <link linkend="paramfplot2d">paramfplot2d</link>
163 </member>
164
165 </simplelist>
166 </refsection>
167 <refsection>
168 <title>Authors</title>
169 <simplelist type="vert">
170 <member>Serge Steer</member>
171 </simplelist>
172 </refsection>
173 <refsection>
174 <title>History</title>
175 <simplelist type="vert">
176 <member>First version April 2011, for Scilab-5.3.2</member>
177 </simplelist>
178 </refsection>
179
180</refentry>
diff --git a/scilab/modules/graphics/help/en_US/2d_plot/paramfplot2d.xml b/scilab/modules/graphics/help/en_US/2d_plot/paramfplot2d.xml
index 572a26f..56b8142 100644
--- a/scilab/modules/graphics/help/en_US/2d_plot/paramfplot2d.xml
+++ b/scilab/modules/graphics/help/en_US/2d_plot/paramfplot2d.xml
@@ -16,13 +16,13 @@
16 </info> 16 </info>
17 <refnamediv> 17 <refnamediv>
18 <refname>paramfplot2d</refname> 18 <refname>paramfplot2d</refname>
19 <refpurpose> animated 2D plot, curve defined by a function</refpurpose> 19 <refpurpose> animated plot of a 2D parametrized curve.</refpurpose>
20 </refnamediv> 20 </refnamediv>
21 <refsynopsisdiv> 21 <refsynopsisdiv>
22 <title>Calling Sequence</title> 22 <title>Calling Sequence</title>
23 <synopsis>paramfplot2d(f,x,theta) 23 <synopsis>paramfplot2d(f,x,theta)
24paramfplot2d(f,x,theta,flag) 24paramfplot2d(f,x,theta,flag)
25paramfplot2d(f,x,theta,flagrect)</synopsis> 25paramfplot2d(f,x,theta,flag,rect)</synopsis>
26 </refsynopsisdiv> 26 </refsynopsisdiv>
27 <refsection> 27 <refsection>
28 <title>Arguments</title> 28 <title>Arguments</title>
@@ -48,7 +48,7 @@ paramfplot2d(f,x,theta,flagrect)</synopsis>
48 <varlistentry> 48 <varlistentry>
49 <term>flag</term> 49 <term>flag</term>
50 <listitem> 50 <listitem>
51 <para>string <literal>'no'</literal> or <literal>'yes'</literal>: If "yes" screen is cleared between two consecutive plots.</para> 51 <para>string <literal>'no'</literal> or <literal>'yes'</literal>: If "yes" screen is not cleared between two consecutive plots.</para>
52 </listitem> 52 </listitem>
53 </varlistentry> 53 </varlistentry>
54 <varlistentry> 54 <varlistentry>
@@ -62,23 +62,49 @@ paramfplot2d(f,x,theta,flagrect)</synopsis>
62 <refsection> 62 <refsection>
63 <title>Description</title> 63 <title>Description</title>
64 <para> 64 <para>
65 Animated plot of the function x--&gt;f(x,t) for t=theta(1),theta(2),etc. 65 Animated plot of the function <literal>x</literal>,
66 f can be a either Scilab function or a dynamically linked routine since 66 <literal>t</literal>--&gt;<literal>f(x,t)</literal> for
67 y=f(x,t) is evaluated as y=feval(x(:),t,f). See feval. 67 <literal>t=theta(1),theta(2),etc</literal>. <literal>f</literal>
68 f: mapping x,t -&gt; f(x,t) = <literal>R^N</literal> valued function for x= vector of <literal>R^N</literal> 68 can be a either Scilab function or a dynamically linked routine
69 and t=real number. x is a N-vector of x-values and for each t in theta, f(x,t)=N-vector of y-values.</para> 69 since <literal>y=f(x,t)</literal> is evaluated as
70 <literal>y=feval(x(:),t,f)</literal>. See <link
71 linkend="feval">feval</link>.
72 </para>
73 <para>
74 <literal>f</literal> is a mapping <literal>x</literal>,
75 <literal>t</literal>--&gt; <literal>f(x,t) = R^N</literal> valued
76 function for <literal>x</literal> a vector of
77 <literal>R^N</literal> and <literal>t</literal> a real number.
78 </para>
70 </refsection> 79 </refsection>
71 <refsection> 80 <refsection>
72 <title>Examples</title> 81 <title>Examples</title>
73 <programlisting role="example"><![CDATA[ 82 <programlisting role="example"><![CDATA[
74deff('y=f(x,t)','y=t*sin(x)') 83deff('y=f(x,t)','y=t*sin(x)')
75x=linspace(0,2*%pi,50);theta=0:0.05:1; 84x=linspace(0,2*%pi,50);theta=0:0.05:1;
76paramfplot2d(f,x,theta); 85clf;paramfplot2d(f,x,theta);
86 ]]></programlisting>
87 <programlisting role="example"><![CDATA[
88function V=twosoliton(x,t)
89 a1=6;s1=2;v1=a1^2;
90 a2=4;s2=40;v2=a2^2;
91
92 f1=exp(-a1*(x-s1-v1*t));
93 f2=exp(-a2*(x-s2-v2*t));
94 r=((a2-1)/(a2+a1))^2;
95 V=2*(v1*f1+v2*f2+2*(a2-a1)^2*f1.*f2+r*(v2*(f1^2).*f2+v1*f1.*(f2^2)))./((1+f1+f2+r*f1.*f2)^2);
96endfunction
97x=linspace(1,100,3000);
98clf;paramfplot2d(twosoliton,x,0:0.05:3);
77 ]]></programlisting> 99 ]]></programlisting>
78 </refsection> 100 </refsection>
79 <refsection role="see also"> 101 <refsection role="see also">
80<title>See Also</title> 102<title>See Also</title>
81 <simplelist type="inline"> 103 <simplelist type="inline">
104 <member>
105 <link linkend="comet">comet</link>
106 </member>
107
82 <member> 108 <member>
83 <link linkend="plot2d">plot2d</link> 109 <link linkend="plot2d">plot2d</link>
84 </member> 110 </member>
diff --git a/scilab/modules/graphics/help/en_US/3d_plot/comet3d.xml b/scilab/modules/graphics/help/en_US/3d_plot/comet3d.xml
new file mode 100644
index 0000000..b51de8e
--- /dev/null
+++ b/scilab/modules/graphics/help/en_US/3d_plot/comet3d.xml
@@ -0,0 +1,178 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<!--
3 * Add some comments about XML file
4-->
5<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" version="5.0-subset Scilab" xml:lang="en_US" xml:id="comet3d">
6 <info>
7 <pubdate>$LastChangedDate: 11-03-2011 $</pubdate>
8 </info>
9 <refnamediv>
10 <refname>comet3d</refname>
11 <refpurpose>3D comet animated plot. </refpurpose>
12 </refnamediv>
13 <refsynopsisdiv>
14 <title>Calling Sequence</title>
15 <synopsis>comet3d(z)</synopsis>
16 <synopsis>comet3d(x,y,z)</synopsis>
17 <synopsis>comet3d(x,y,fun)</synopsis>
18 <synopsis>comet3d(x,y,z,p)</synopsis>
19 <synopsis>comet3d(x,y,fun,p)</synopsis>
20 <synopsis>comet3d(...,"colors",c)</synopsis>
21 </refsynopsisdiv>
22 <refsection>
23 <title>Parameters</title>
24 <variablelist>
25 <varlistentry>
26 <term>x</term>
27 <listitem>
28 <para>
29 a real vector or matrix. If omitted, it is assumed to be the vector
30 <literal>1:nz</literal> where <literal>nz</literal> is the
31 number of curve points given by the <literal>z</literal>
32 parameter.
33 </para>
34 </listitem>
35 </varlistentry>
36 <varlistentry>
37 <term>y</term>
38 <listitem>
39 <para>
40 a real vector or matrix. If omitted, it is assumed to be the vector
41 <literal>1:nz</literal> where <literal>nz</literal> is the
42 number of curve points given by the <literal>z</literal>
43 parameter.
44 </para>
45 </listitem>
46 </varlistentry>
47
48 <varlistentry>
49 <term>z</term>
50 <listitem>
51 <para>
52 a real vector of length <literal>nz</literal> or a matrix with <literal>nz</literal> rows.
53 </para>
54 </listitem>
55 </varlistentry>
56 <varlistentry>
57 <term>p</term>
58 <listitem>
59 <para>
60 a real scalar in the interval<literal>[0 1[</literal>. Default value is 0.1.
61 </para>
62 </listitem>
63 </varlistentry>
64 <varlistentry>
65 <term>fun</term>
66 <listitem>
67 <para>
68 a scilab function with calling sequence <literal>z=fun(x,y)</literal>.
69 </para>
70 </listitem>
71 </varlistentry>
72 <varlistentry>
73 <term>c</term>
74 <listitem>
75 <para>
76 a vector of <literal>ny</literal> color index.
77 </para>
78 </listitem>
79 </varlistentry>
80 </variablelist>
81 </refsection>
82 <refsection>
83 <title>Description</title>
84 <para>
85 If <literal>(x,y,z)</literal> are three vectors with the same number of elements, this function draws a 3D comet
86 animated plot. The plot is made of three parts:
87 <variablelist>
88 <varlistentry>
89 <term>a head</term>
90 mark that shows the current <literal>(x(i),y(i),z(i))</literal> position.
91 <listitem>
92 <para>
93 </para>
94 </listitem>
95 </varlistentry>
96 <varlistentry>
97 <term>a body</term> that shows the trailing curve that
98 follows the head: the
99 <literal>(x(i-k:i),y(i-k:i),z(i-k:i))</literal>) part of the curve.
100 <listitem>
101 <para>
102 </para>
103 </listitem>
104 </varlistentry>
105 <varlistentry>
106 <term>a tail</term>
107 that shows the <literal>(x(1:i-k),y(1:i-k),z(1:i-k))</literal> part of the curve.
108 <listitem>
109 <para>
110 </para>
111 </listitem>
112 </varlistentry>
113 </variablelist>
114 <para>
115 if <literal>z</literal> is a matrix and
116 <literal>(x,y)</literal> are vectors then animated curves
117 are drawn for each triple <literal>(x,y,z(:,l))</literal>.
118 in this case <literal>nz</literal> is the number of rows of
119 <literal>z</literal>.
120 </para>
121 <para>
122 if <literal>x,y,z</literal> are matrices with the same dimensions then animated curves
123 are drawn for each triple <literal>(x(:,l),y(:,l),z(:,l))</literal>.
124 </para>
125
126 <para>
127
128 <literal>comet3d(x,y,fun,...)</literal> computes the
129 <literal>z</literal> vector as
130 <literal>z(i)=fun(x(i),y(i))</literal>
131 </para>
132 <para>
133 <literal>comet3d(...,p)</literal> can be used to set the
134 relative length of the body. <literal>k</literal> is defined
135 as <literal>k = round(p*nz)</literal>.
136 </para>
137
138 </para>
139 </refsection>
140 <refsection>
141 <title>Examples</title>
142 <programlisting role="example"><![CDATA[
143t = linspace(-%pi,%pi,500);
144clf();comet3d(sin(5*t),sin(t),t^2)
145 ]]></programlisting>
146 <programlisting role="example"><![CDATA[
147t = linspace(-%pi,%pi,500)';
148clf();comet3d(sin(5*t),sin(t),[t^2,ones(t)])
149 ]]></programlisting>
150 <programlisting role="example"><![CDATA[
151function z=traj(x,y),z=1.5*sin(x^2)*cos(y),endfunction
152clf();comet3d(cos(t),sin(t),traj)
153 ]]></programlisting>
154 </refsection>
155 <refsection>
156 <title>See Also</title>
157 <simplelist type="inline">
158 <member>
159 <link linkend="comet" >comet</link>
160 </member>
161 </simplelist>
162 </refsection>
163
164 <refsection>
165 <title>Authors</title>
166 <simplelist type="vert">
167 <member>Serge Steer</member>
168 </simplelist>
169 </refsection>
170
171 <refsection>
172 <title>History</title>
173 <simplelist type="vert">
174 <member>First version April 2011, for Scilab-5.3.2</member>
175 </simplelist>
176 </refsection>
177
178</refentry>
diff --git a/scilab/modules/graphics/macros/comet.sci b/scilab/modules/graphics/macros/comet.sci
new file mode 100644
index 0000000..bca390f
--- /dev/null
+++ b/scilab/modules/graphics/macros/comet.sci
@@ -0,0 +1,173 @@
1// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2// Copyright (C) 2011 - INRIA - Serge Steer <serge.steer@inria.fr>
3//
4// This file must be used under the terms of the CeCILL.
5// This source file is licensed as described in the file COPYING, which
6// you should have received as part of this distribution. The terms
7// are also available at;
8// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
9
10function comet(varargin)
11//Comet-like trajectory.
12// comet(y) displays an animated comet plot of the vector y.
13// comet(x,y) displays an animated comet plot of vector y vs. x.
14// comet(x,y,p) uses a comet of length p*size(y,'*'). Default is p = 0.1.
15
16// Example:
17// t = linspace(0,10*%pi,500);
18// clf();comet(t.*sin(t),t.*cos(t))
19//
20// function y=traj(x),y=1.5*sin(x^2),endfunction
21// clf();comet(linspace(0,5,500),traj)
22//
23// clf();comet(linspace(-2,4,500),(%s-3)/(%s^3+2*%s^2+1))
24
25 nv=size(varargin)
26 if varargin(nv-1)=='colors' then
27 c=round(varargin(nv))
28 if type(c)<>1|~isreal(c) then
29 error(msprintf(_("%s: Wrong type for argument %d: Real vector expected.\n"),"comet",nv))
30 end
31 varargin=list(varargin(1:$-2))
32 else
33 c=[]
34 end
35 select size(varargin)
36 case 1 then //y
37 y=varargin(1)
38 if or(size(y)==1) then
39 x=1:size(y,'*')
40 else
41 x=1:size(y,1)
42 end
43 p=0.1
44 case 2 then //x,y
45 [x,y]=varargin(1:2)
46 p=0.1
47 case 3 then //x,y,p
48 [x,y,p]=varargin(1:3)
49 else
50 error(msprintf(_("%s: Wrong number of input arguments: %d to %d expected.\n"),"comet",1,3))
51 end
52 if type(x)<>1|~isreal(x) then
53 error(msprintf(_("%s: Wrong type for argument %d: Real vector expected.\n"),"comet",1))
54 end
55 if or(type(y)==[11 13]) then //a function
56 prot=funcprot();funcprot(0)
57 y=feval(x,y)
58 funcprot(prot)
59 elseif type(y)==2 then //a polynomial
60 y=horner(y,x)
61 elseif typeof(y)=='rational' then //a rational fraction
62 y=horner(y,x)
63 end
64 if type(y)<>1|~isreal(y) then
65 error(msprintf(_("%s: Wrong type for argument %d: Real vector expected.\n"),"comet",2))
66 end
67 if type(p)<>1|~isreal(p)|size(p,'*')>1 then
68 error(msprintf(_("%s: Wrong type for argument %d: Real scalar expected.\n"),"comet",3))
69 end
70 if p<0|p>=1 then
71 error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the interval %s.\n"),"comet",3,"[0 1["))
72 end
73
74 if or(size(x)==1) then
75 x=x(:)
76 n=size(x,1)
77 if or(size(y)==1) then
78 if n<>size(y,'*') then
79 error(msprintf(_("%s: Incompatible input arguments #%d and #%d: Same sizes expected.\n"),"comet",1,2))
80 end
81 y=y(:)
82 m=1
83 else
84 m=size(y,2)
85 if size(y,1)<>n then
86 error(msprintf(_("%s: Incompatible input arguments #%d and #%d: Same number of rows expected.\n"),"comet",1,2))
87 end
88 x=x*ones(1,m)
89 end
90 else
91 n=size(x,1)
92 m=size(x,2)
93 if or(size(y)<>size(x)) then
94 error(msprintf(_("%s: Incompatible input arguments #%d and #%d: Same sizes expected.\n"),"comet",1,2))
95 end
96 end
97 fig=gcf();
98 if c==[] then
99 c=1:m
100 else
101 if size(c,'*')<>m then
102 error(msprintf(_("%s: Wrong size for argument %d: %d expected.\n"),"comet",nv,m))
103 end
104 if min(c)<1|max(c)>size(fig.color_map,1) then
105 error(msprintf(_( "%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),"comet",nv,"1,...,"+string(size(fig.color_map,1))))
106 end
107 end
108 axes=gca();
109
110 if axes.children==[] then
111 axes.data_bounds=[min(x) min(y);max(x) max(y)];
112 axes.axes_visible="on";
113 else
114 axes.data_bounds=[min(axes.data_bounds(1,:), [min(x) min(y)]);
115 max(axes.data_bounds(2,:), [max(x) max(y)])];
116 end
117 //create the head, body and tail polylines
118 drawlater()
119 tail=[];body=[];head=[];
120 for l=1:m
121 xpoly([],[]);tail(l)=gce();
122 tail(l).foreground=c(l);
123 xpoly([],[]);body(l)=gce();
124 body(l).foreground=c(l);
125 body(l).thickness=2;
126 xpoly([],[],'marks');head(l)=gce();
127 head(l).mark_size_unit='point';
128 head(l).mark_size=6;
129 head(l).mark_style=9;
130 head(l).mark_foreground=c(l);
131 end
132 show_window();
133
134
135function anim()
136//animation loop
137 k = round(p*n);
138 step=ceil(n/200); //used to speed up the drawing
139
140 for i=1:n
141 for l=1:m
142 head(l).data=[x(i),y(i,l)];
143 if i<=k then
144 body(l).data= [body(l).data;[x(i,l),y(i,l)]];
145 else
146 body(l).data= [body(l).data(2:$,:);[x(i,l),y(i,l)]];
147 tail(l).data=[ tail(l).data;[x(i-k+1,l),y(i-k+1,l)]];
148 end
149 end
150 if modulo(i,step)==0 then
151 fig.immediate_drawing = "on"
152 fig.immediate_drawing = "off"
153 end
154 end
155 fig.immediate_drawing = "on"
156 fig.immediate_drawing = "off"
157 for i=1:k
158 for l=1:m
159 body(l).data= body(l).data(2:$,:);
160 tail(l).data=[tail(l).data;[x(n-k+i,l),y(n-k+i,l)]];
161 end
162 if modulo(i,step)==0 then
163 //draw(axes),
164 fig.immediate_drawing = "on"
165 fig.immediate_drawing = "off"
166 end
167 end
168 fig.immediate_drawing = "on"
169 delete(body)
170endfunction
171//not to generate an error message if the window is closed
172exec(anim,-1,'errcatch')
173endfunction
diff --git a/scilab/modules/graphics/macros/comet3d.sci b/scilab/modules/graphics/macros/comet3d.sci
new file mode 100644
index 0000000..aaadc3c
--- /dev/null
+++ b/scilab/modules/graphics/macros/comet3d.sci
@@ -0,0 +1,198 @@
1// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2// Copyright (C) 2011 - INRIA - Serge Steer <serge.steer@inria.fr>
3//
4// This file must be used under the terms of the CeCILL.
5// This source file is licensed as described in the file COPYING, which
6// you should have received as part of this distribution. The terms
7// are also available at;
8// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
9
10function comet3d(varargin)
11//Comet-like trajectory.
12// comet(y) displays an animated comet plot of the vector y.
13// comet(x,y) displays an animated comet plot of vector y vs. x.
14// comet(x,y,p) uses a comet of length p*size(y,'*'). Default is p = 0.1.
15
16// Example:
17// t = linspace(-%pi,%pi,500);
18// clf();comet3d(sin(5*t),sin(t),t^2)
19//
20// function z=traj(x,y),z=1.5*sin(x^2)*cos(y),endfunction
21// clf();comet3d(cos(t),sin(t),traj)
22//
23 nv=size(varargin)
24 if varargin(nv-1)=='colors' then
25 c=round(varargin(nv))
26 if type(c)<>1|~isreal(c) then
27 error(msprintf(_("%s: Wrong type for argument %d: Real vector expected.\n"),"comet3d",nv))
28 end
29 varargin=list(varargin(1:$-2))
30 else
31 c=[]
32 end
33 select size(varargin)
34
35 case 1 then //z
36 z=varargin(1)
37 if or(size(z)==1) then
38 x=1:size(z,'*')
39 else
40 x=1:size(z,1)
41 end
42 y=x
43 p=0.1
44 case 3 then //x,y,z
45 [x,y,z]=varargin(1:3)
46 p=0.1
47 case 4 then //x,y,z,p
48 [x,y,z,p]=varargin(1:4)
49 else
50 error(msprintf(_("%s: Wrong number of input arguments: %d or %d to %d expected.\n"),"comet3d",1,3,4))
51 end
52
53
54 if type(x)<>1|~isreal(x) then
55 error(msprintf(_("%s: Wrong type for argument %d: Real vector expected.\n"),"comet3d",1))
56 end
57 if type(y)<>1|~isreal(x) then
58 error(msprintf(_("%s: Wrong type for argument %d: Real vector expected.\n"),"comet3d",1))
59 end
60
61 if (type(z)<>1|~isreal(z))&and(type(z)<>[11 13]) then
62 error(msprintf(_("%s: Wrong type for argument %d: Real vector expected.\n"),"comet3d",3))
63 end
64
65
66 if or(type(z)==[11 13]) then
67 x=x(:);y=y(:)
68 n=size(x,'*')
69 m=1
70 if n<>size(y,'*') then
71 error(msprintf(_("%s: Incompatible input arguments #%d and #%d: Same sizes expected.\n"),"comet3d",1,2))
72 end
73 prot=funcprot();funcprot(0)
74 zz=z;
75 z=zeros(n,1);
76 for i=1:n
77 z(i)=zz(x(i),y(i))
78 end
79 funcprot(prot)
80 else
81 if or(size(z)==1) then
82 m=1
83 z=z(:)
84 n=size(z,'*')
85 else
86 [n,m]=size(z)
87 end
88 if or(size(x)==1) then
89 x=x(:)
90 if size(x,'*')<>n then
91 error(msprintf(_("%s: Wrong size for argument %d: %d expected.\n"),"comet3d",1,n))
92 end
93 x=x*ones(1,m)
94 else
95 if or(size(x)<>size(z)) then
96 error(msprintf(_("%s: Incompatible input arguments #%d and #%d: Same sizes expected.\n"),"comet3d",1,3))
97 end
98 end
99 if or(size(y)==1) then
100 y=y(:)
101 if size(y,'*')<>n then
102 error(msprintf(_("%s: Wrong size for argument %d: %d expected.\n"),"comet3d",2,n))
103 end
104 y=y*ones(1,m)
105 else
106 if or(size(y)<>size(z)) then
107 error(msprintf(_("%s: Incompatible input arguments #%d and #%d: Same sizes expected.\n"),"comet3d",2,3))
108 end
109
110 end
111 end
112
113
114 if type(p)<>1|~isreal(p)|size(p,'*')>1 then
115 error(msprintf(_("%s: Wrong type for argument %d: Real scalar expected.\n"),"comet3d",3))
116 end
117 if p<0|p>=1 then
118 error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the interval %s.\n"),"comet3d",3,"[0 1["))
119 end
120 fig=gcf();
121 if c==[] then
122 c=1:m
123 else
124 if size(c,'*')<>m then
125 error(msprintf(_("%s: Wrong size for argument %d: %d expected.\n"),"comet",nv,m))
126 end
127 if min(c)<1|max(c)>size(fig.color_map,1) then
128 error(msprintf(_( "%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),"comet",nv,"1,...,"+string(size(fig.color_map,1))))
129 end
130 end
131 axes=gca();
132 axes.view='3d'
133
134
135 if axes.children==[] then
136 axes.data_bounds=[min(x) min(y) min(z);max(x) max(y) max(z)];
137 axes.axes_visible="on";
138 axes.box="on";
139 else
140 axes.data_bounds=[min(axes.data_bounds(1,:), [min(x) min(y) min(z)]);
141 max(axes.data_bounds(2,:), [max(x) max(y) max(z)])];
142 end
143 //create the head, body and tail polylines
144 drawlater()
145 for l=1:m
146 xpoly([],[]);tail(l)=gce();
147 tail(l).foreground=c(l);
148
149 xpoly([],[]);body(l)=gce();
150 body(l).foreground=c(l); body(l).thickness=2;
151 xpoly([],[],'marks');head(l)=gce();
152 head(l).mark_size_unit='point';
153 head(l).mark_size=6;
154 head(l).mark_style=9;
155 head(l).mark_foreground=c(l);
156 end
157 show_window();
158
159 function anim()
160 //animation loop
161 k = round(p*n);
162 step=ceil(n/200); //used to speed up the drawing
163
164 for i=1:n
165 for l=1:m
166 head(l).data=[x(i,l),y(i,l),z(i,l)];
167 if i<=k then
168 body(l).data= [body(l).data;[x(i,l),y(i,l),z(i,l)]];
169 else
170 body(l).data= [body(l).data(2:$,:);[x(i,l),y(i,l),z(i,l)]];
171 tail(l).data=[ tail(l).data;[x(i-k,l),y(i-k,l),z(i-k,l)]];
172 end
173 end
174 if modulo(i,step)==0 then
175 fig.immediate_drawing = "on"
176 fig.immediate_drawing = "off"
177 end
178 end
179 drawnow(),drawlater()
180
181 for i=n:n+k
182 for l=1:m
183 body(l).data= body(l).data(2:$,:);
184 tail(l).data=[ tail(l).data;[x(i-k,l),y(i-k,l),z(i-k,l)]];
185 end
186 if modulo(i,step)==0 then
187 //draw(axes),
188 fig.immediate_drawing = "on"
189 fig.immediate_drawing = "off"
190 end
191 end
192 delete(body)
193 drawnow()
194 endfunction
195 //not to generate an error message if the window is closed
196 //exec(anim,-1,'errcatch')
197 exec(anim,-1)
198endfunction