~ubuntu-branches/ubuntu/hoary/scilab/hoary

« back to all changes in this revision

Viewing changes to demos/surface/bezier.sci

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2005-01-09 22:58:21 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050109225821-473xr8vhgugxxx5j
Tags: 3.0-12
changed configure.in to build scilab's own malloc.o, closes: #255869

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
function gammatest (N)
2
 
// Bezier curve approximating a circle
3
 
// Copyright INRIA
4
 
[lhs,rhs] =argn(0);
5
 
if rhs < 1 ;N=[10,20,50,100];end
6
 
x=linspace(0,1,100);
7
 
plot2d(cos(2*%pi*x)',sin(2*%pi*x)',1,"151"," ",[-2,-2,2,2]);
8
 
xtitle('Bezier curve approximating a circle')
9
 
icol=2
10
 
for n=N ; 
11
 
  t=sqrt(linspace(0,1,n));
12
 
  p=[cos(2*%pi*t);sin(2*%pi*t)];
13
 
  y=bezier(p,x);
14
 
  plot2d(y(1,:)',y(2,:)',icol,"000");
15
 
  icol=icol+1;
16
 
end;
17
 
// endfunction
18
 
 
19
 
 
20
 
function beziertest
21
 
// a random polygon and a bezier curve 
22
 
// Copyright INRIA
23
 
plot2d(-0.2,-0.2,0,"011"," ",[-0.2,-0.2,1.2,1.2]);
24
 
xtitle('Bezier Test : random polygon and bezier curve')
25
 
rand('uniform');
26
 
p=rand(2,5);
27
 
t=linspace(0,1,300);
28
 
s=bezier(p,t);
29
 
plot2d(p(1,:)',p(2,:)',1,"000");
30
 
plot2d(s(1,:)',s(2,:)',2,"000");
31
 
// endfunction
32
 
 
33
 
function bezier3dtest ()
34
 
// Show a Beziercurve of dimension 3
35
 
// Copyright INRIA
36
 
p=[-1,-1,-1;0,-1,-1;1,0,0;1,1,0;0,1,1;-1,1,0]';
37
 
bezier3d(p);
38
 
// endfunction
39
 
 
40
 
 
41
 
function beziersurftest
42
 
// Show a Bezier surface
43
 
// Copyright INRIA
44
 
x=linspace(-%pi,%pi,5)
45
 
[x,y]=field(x,x);
46
 
z= 3*sin(x).*cos(y)
47
 
[xb,yb,zb]=beziersurface(x,y,z);
48
 
xsetech([0,0,1.0,0.5]);         
49
 
plot3d3(x,y,z);
50
 
xtitle('A first surface ');
51
 
xsetech([0,0.5,1.0,0.5])
52
 
plot3d2(xb,yb,zb,-1,35,45," ",[4,2,3]);
53
 
xtitle('The bezier interpolated surface (n=10)');
54
 
xsetech([0,0,1,1]);
55
 
// endfunction
56
 
 
57
 
function c1test
58
 
// Show how two bezier surfaces can be joined.
59
 
// Copyright INRIA
60
 
// first surface 
61
 
x1=dup(-0.5:0.25:0.5,5);
62
 
y1=dup([0,0,0,0,1],5);
63
 
z1=dup(2:0.25:3,5)';
64
 
[xb1,yb1,zb1]=beziersurface(x1,y1,z1,10);
65
 
// second surface 
66
 
x2=dup(-0.5:0.25:0.5,5);
67
 
y2=[(ones(4,5));[0,0,0,0,0]];
68
 
z2=-dup(-1:0.25:0,5)';
69
 
[xb2,yb2,zb2]=beziersurface(x2,y2,z2,10);
70
 
// a surface to link the two previous ones 
71
 
x=zeros(5,5); y=x; z=x;
72
 
 
73
 
x(1,:)=x1(1,:); x(2,:)=x(1,:)-(x1(2,:)-x1(1,:));
74
 
x(5,:)=x2(1,:); x(4,:)=x(5,:)-(x2(2,:)-x2(1,:));
75
 
x(3,:)=(x(4,:)+x(2,:))/2;
76
 
y(1,:)=y1(1,:); y(2,:)=y(1,:)-(y1(2,:)-y1(1,:));
77
 
y(5,:)=y2(1,:); y(4,:)=y(5,:)-(y2(2,:)-y2(1,:));
78
 
y(3,:)=(y(4,:)+y(2,:))/2;
79
 
z(1,:)=z1(1,:); z(2,:)=z(1,:)-(z1(2,:)-z1(1,:));
80
 
z(5,:)=z2(1,:); z(4,:)=z(5,:)-(z2(2,:)-z2(1,:));
81
 
z(3,:)=(z(4,:)+z(2,:))/2;
82
 
A=35,T=50,L=" ",EB=[4,2,0]
83
 
[xb,yb,zb]=beziersurface(x,y,z,10);
84
 
xsetech([0,0,1,1]);
85
 
xtitle('how two bezier surfaces can be joined');
86
 
xsetech([0,0,0.5,0.5]);plot3d2(xb1,yb1,zb1,-1,A,T,L,EB); 
87
 
//xsetech([0.5,0,0.5,0.5]);plot3d2(xb,yb,zb,-1,A,T,L,EB); 
88
 
xsetech([0,0.5,0.5,0.5]);plot3d2(xb2,yb2,zb2,-1,A,T,L,EB);
89
 
xsetech([0.5,0.0,0.5,1.0]);
90
 
[n1,p1]=size(xb1);
91
 
[n2,p2]=size(xb);
92
 
plot3d2([xb1;xb;xb2],[yb1;yb;yb2],[zb1;zb;zb2],-1,A,T,L,EB);
93
 
xsetech([0,0,1,1]);
94
 
// endfunction
95
 
 
96
 
 
97
 
 
98
 
 
99
 
 
100
 
 
101
 
 
102
 
 
103