2
// Bezier curve approximating a circle
5
if rhs < 1 ;N=[10,20,50,100];end
7
plot2d(cos(2*%pi*x)',sin(2*%pi*x)',1,"151"," ",[-2,-2,2,2]);
8
xtitle('Bezier curve approximating a circle')
11
t=sqrt(linspace(0,1,n));
12
p=[cos(2*%pi*t);sin(2*%pi*t)];
14
plot2d(y(1,:)',y(2,:)',icol,"000");
21
// a random polygon and a bezier curve
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')
29
plot2d(p(1,:)',p(2,:)',1,"000");
30
plot2d(s(1,:)',s(2,:)',2,"000");
33
function bezier3dtest ()
34
// Show a Beziercurve of dimension 3
36
p=[-1,-1,-1;0,-1,-1;1,0,0;1,1,0;0,1,1;-1,1,0]';
41
function beziersurftest
42
// Show a Bezier surface
44
x=linspace(-%pi,%pi,5)
47
[xb,yb,zb]=beziersurface(x,y,z);
48
xsetech([0,0,1.0,0.5]);
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)');
58
// Show how two bezier surfaces can be joined.
61
x1=dup(-0.5:0.25:0.5,5);
62
y1=dup([0,0,0,0,1],5);
64
[xb1,yb1,zb1]=beziersurface(x1,y1,z1,10);
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;
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);
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]);
92
plot3d2([xb1;xb;xb2],[yb1;yb;yb2],[zb1;zb;zb2],-1,A,T,L,EB);