File: Macros.sci

package info (click to toggle)
scilab 2.4-1
  • links: PTS
  • area: non-free
  • in suites: potato, slink
  • size: 55,196 kB
  • ctags: 38,019
  • sloc: ansic: 231,970; fortran: 148,976; tcl: 7,099; makefile: 4,585; sh: 2,978; csh: 154; cpp: 101; asm: 39; sed: 5
file content (207 lines) | stat: -rw-r--r-- 6,156 bytes parent folder | download
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
function showinstr(mac)
if type(mac)==11 then
  [in,out,txt]=string(mac)
  x_message(txt)
end


function [X,Y]=field(x,y)
// x and y are two vectors defining a grid
// X and Y are two matrices which gives the grid point coordinates
//-------------------------------------------------------------
// Copyright INRIA
[rx,cx]=size(x);
[ry,cy]=size(y);
if rx<>1, write(%io(2),"x must be a row vector");return;end;
if ry<>1, write(%io(2),"y must be a row vector");return;end;
X=x.*.ones(cy,1);
Y=y'.*.ones(1,cx);

function plot3d3(x,y,z,vect,T,A,leg,flags,ebox)
// mesh draw of a solid surface described 
// by a set of points ( as in the plot3d2 macro : see below ) 
// the mesh is drawn using the colums and rows of [x,y,z]
//---------------------------------------------------------
// Copyright INRIA
[lhs,rhs]=argn(0);
if rhs <= 3; vect=-1;end
if rhs >= 4 & vect<>-1 
  nobjs=prod(size(vect))+1;
  [rx,cx]=size(x);
  vect1=[0,vect,rx];
  xx=[],yy=[],zz=[];
  for i=1:nobjs; 
    xx=[x(vect1(i)+1:vect1(i+1),:),xx]
    yy=[y(vect1(i)+1:vect1(i+1),:),yy]
    zz=[z(vect1(i)+1:vect1(i+1),:);zz]
  end
else
  xx=x;yy=y;zz=z;
end
[n,p]=size(z);
if rhs < 9 then ebox=[-1,1,-1,1,-1,1];end 
if rhs < 8 then flags=[3,4,2,3];end
if rhs < 7 then leg=" ";end 
if rhs < 6 then A=45;end 
if rhs < 5 then T=35;end 
param3d1(xx,yy,list(zz,flags(1)*ones(1,p)),T,A,leg,flags(3:4),ebox) 
param3d1(xx',yy',list(zz',flags(2)*ones(1,n)),T,A,leg,[0,flags(4)],ebox) 

function [xx,yy,zz]=nf3d(x,y,z)
// 3d coding transformation 
// from facets coded in three matrices x,y,z to scilab code for facets 
// accepted by plot3d 
//---------------------------------------------------------
// Copyright INRIA
[n1,n2]=size(x)
ind=ones(1,n1-1).*.[0 1 n1+1 n1]+ (1:n1-1).*.[1 1 1 1];
// ind=[1,2,n1+2,n1+1 , 2,3,n1+3,n1+2, ....  ,n1-1,n1,2n1,2n1-1
ind2=ones(1,n2-1).*.ind+((0:n2-2)*n1).*.ones(ind);
nx=prod(size(ind2))
xx=matrix(x(ind2),4,nx/4);
yy=matrix(y(ind2),4,nx/4);
zz=matrix(z(ind2),4,nx/4);

function plot3d2(x,y,z,vect,varargin)
// plot3d2(x,y,z,vect,T,A,leg,flags,ebox)
// (x,y,z) description of a set of surfaces 
// to Scilab description + call to plot3d 
// (x,y,z) are three matrices which describe a surface 
// the surface is composed of four sided polygons 
// The x-coordinates of a facet are given by x(i,j),x(i+1,j),x(i,j+1),
//	x(i+1,j+1)
// the vect vector is used when multiple surfaces are coded 
// in the same (x,y,z) matrices. vect(j) gives the line 
// at which the coding of the jth surface begins 
// if vect==-1 means that vect is useless
// Copyright INRIA
//---------------------------------------------------------
[lhs,rhs]=argn(0);
if rhs <= 3; vect=-1;varargin=list();end
if rhs >= 4 & vect<>-1 then
  nobjs=prod(size(vect))+1;
  [rx,cx]=size(x);
  vect1=[0,vect,rx];
  xx=[],yy=[],zz=[];
  for i=1:nobjs; 
    [xxl,yyl,zzl]=nf3d(x(vect1(i)+1:vect1(i+1),:),...
	y(vect1(i)+1:vect1(i+1),:),...
	z(vect1(i)+1:vect1(i+1),:)),...
	xx=[xx,xxl];yy=[yy,yyl];zz=[zz,zzl];
  end;
else 
  [xx,yy,zz]=nf3d(x,y,z)
end
plot3d(xx,yy,zz,varargin(:))

function [z]=dup(x,n)
// utility 
// x is a vector this function returns [x,x,x,x...] or [x;x;x;x;..]
// depending on x 
// Copyright INRIA
[nr,nc]=size(x)
if nr==1 then y=ones(n,1) ; z= x.*.y ; 
	else if nc<>1 then error("dup : x must be a vector");
	else y=ones(1,n) ; z= x.*.y ; end;end

function [z] = bezier(p,t)
//comment : Computes a  Bezier curves.
//For a test try:
//beziertest; bezier3dtest; nurbstest; beziersurftest; c1test;
//Uses the following functions:
//bezier, bezier3d, nurbs, beziersurface
//endcomment
//reset();
// Evaluate sum p_i B_{i,n}(t) the easy and direct way.
// p must be a k x n+1 matrix (n+1) points, dimension k.
// Copyright INRIA
	n=size(p,'c')-1;// i=nonzeros(t~=1);
	t1=(1-t); t1z= find(t1==0.0); t1(t1z)= ones(t1z);
	T=dup(t./t1,n)';
	b=[((1-t')^n),(T.*dup((n-(1:n)+1)./(1:n),size(t,'c')))];
	b=cumprod(b,'c');
	if (size(t1z,'c')>0); b(t1z,:)= dup([ 0*ones(1,n),1],size(t1z,'c')); end;
	z=p*b';
// endfunction


function bezier3d (p)
// Shows a 3D Bezier curve and its polygon
// Copyright INRIA
	t=linspace(0,1,300);
	s=bezier(p,t);
	dh=xget("dashes");
	xset("dashes",3)
	param3d(p(1,:),p(2,:),p(3,:),34,45)
	xset("dashes",4);
	param3d(s(1,:),s(2,:),s(3,:),34,45,"x@y@z",[0,0])
	xset("dashes",dh);
	xtitle('A 3d polygon and its Bezier curve');
// endfunction	


function [X,Y,Z]=beziersurface (x,y,z,n)
// Compute a Bezier surface. Return {bx,by,bz}.
// Copyright INRIA
	[lhs,rhs]=argn(0);
	if rhs <= 3 ; n=20;end 
	t=linspace(0,1,n);
	n=size(x,'r')-1; // i=nonzeros(t~=1);
	t1=(1-t); t1z= find(t1==0.0); t1(t1z)= ones(t1z);
	T=dup(t./t1,n)';
	b1=[((1-t')^n),(T.*dup((n-(1:n)+1)./(1:n),size(t,'c')))];
	b1=cumprod(b1,'c');
	if (size(t1z,'c')>0); 
		b1(t1z,:)= dup([ 0*ones(1,n),1],size(t1z,'c')); end;

	n=size(x,'c')-1; // i=nonzeros(t~=1);
	t1=(1-t); t1z= find(t1==0.0); t1(t1z)= ones(t1z);
	T=dup(t./t1,n)';
	b2=[((1-t')^n),(T.*dup((n-(1:n)+1)./(1:n),size(t,'c')))];
	b2=cumprod(b2,'c');
	if (size(t1z,'c')>0); 
		b2(t1z,:)= dup([ 0*ones(1,n),1],size(t1z,'c')); end;
	X=b1*x*b2';Y=b1*y*b2';Z=b1*z*b2';
// endfunction

function cplxmap(z,w,varargin)
//cplxmap(z,w,T,A,leg,flags,ebox)
//cplxmap Plot a function of a complex variable.
//       cplxmap(z,f(z))
// Copyright INRIA
x = real(z);
y = imag(z);
u = real(w);
v = imag(w);
M = max(u);
m = min(u);
s = ones(size(z));
//mesh(x,y,m*s,blue*s);
//hold on
[X,Y,U]=nf3d(x,y,u);
[X,Y,V]=nf3d(x,y,v);
Colors = sum(V,'r');
Colors = Colors - min(Colors);
Colors = 32*Colors/max(Colors);
plot3d1(X,Y,list(U,Colors),varargin(:))


function cplxroot(n,m,varargin)
//cplxroot(n,m,T,A,leg,flags,ebox)
//CPLXROOT Riemann surface for the n-th root.
//       CPLXROOT(n) renders the Riemann surface for the n-th root.
//       CPLXROOT, by itself, renders the Riemann surface for the cube root.
//       CPLXROOT(n,m) uses an m-by-m grid.  Default m = 20.
// Use polar coordinates, (r,theta).
// Cover the unit disc n times.
// Copyright INRIA
[lhs,rhs]=argn(0)
if rhs  < 1, n = 3; end
if rhs  < 2, m = 20; end
r = (0:m)'/m;
theta = - %pi*(-n*m:n*m)/m;
z = r * exp(%i*theta);
s = r.^(1/n) * exp(%i*theta/n);
cplxmap(z,s,varargin(:))