File: Macros.sci

package info (click to toggle)
scilab 4.0-12
  • links: PTS
  • area: non-free
  • in suites: etch, etch-m68k
  • size: 100,640 kB
  • ctags: 57,333
  • sloc: ansic: 377,889; fortran: 242,862; xml: 179,819; tcl: 42,062; sh: 10,593; ml: 9,441; makefile: 4,377; cpp: 1,354; java: 621; csh: 260; yacc: 247; perl: 130; lex: 126; asm: 72; lisp: 30
file content (144 lines) | stat: -rw-r--r-- 3,811 bytes parent folder | download | duplicates (2)
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
function showinstr(mac)
	if type(mac)==11 then
		[in,out,txt]=string(mac)
		x_message(txt)
	end
endfunction


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);
endfunction

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
endfunction


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');
	current_axe = gca();current_axe.title.font_size = 3;
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(:))
endfunction

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(:))
endfunction