diff options
Diffstat (limited to 'modules/graphics/demos/bezier')
-rwxr-xr-x | modules/graphics/demos/bezier/Macros.sci | 96 | ||||
-rwxr-xr-x | modules/graphics/demos/bezier/bezier.dem.gateway.sce | 19 | ||||
-rwxr-xr-x | modules/graphics/demos/bezier/bezier3dtest.sce | 21 | ||||
-rwxr-xr-x | modules/graphics/demos/bezier/beziersurftest.sce | 33 | ||||
-rwxr-xr-x | modules/graphics/demos/bezier/beziertest.sce | 30 | ||||
-rwxr-xr-x | modules/graphics/demos/bezier/c1test.sce | 61 | ||||
-rwxr-xr-x | modules/graphics/demos/bezier/gammatest.sce | 42 |
7 files changed, 302 insertions, 0 deletions
diff --git a/modules/graphics/demos/bezier/Macros.sci b/modules/graphics/demos/bezier/Macros.sci new file mode 100755 index 000000000..28ebf02d4 --- /dev/null +++ b/modules/graphics/demos/bezier/Macros.sci @@ -0,0 +1,96 @@ +// +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) INRIA +// +// This file is distributed under the same license as the Scilab package. +// + +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 + //------------------------------------------------------------- + [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 + [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. + 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 + 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}. + [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 diff --git a/modules/graphics/demos/bezier/bezier.dem.gateway.sce b/modules/graphics/demos/bezier/bezier.dem.gateway.sce new file mode 100755 index 000000000..985493b68 --- /dev/null +++ b/modules/graphics/demos/bezier/bezier.dem.gateway.sce @@ -0,0 +1,19 @@ +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) INRIA +// +// This file is released under the 3-clause BSD license. See COPYING-BSD. + +demopath = get_absolute_file_path("bezier.dem.gateway.sce"); + +exec(demopath+"/Macros.sci"); + +subdemolist=[ +"Gammatest" , "gammatest.sce"; +"2D curve Bezier test" , "beziertest.sce"; +"3D curve Bezier test" , "bezier3dtest.sce"; +"Bezier surface test" , "beziersurftest.sce" +"Bezier surface test 2" , "c1test.sce"]; + + +subdemolist(:,2) = demopath + subdemolist(:,2); +clear demopath; diff --git a/modules/graphics/demos/bezier/bezier3dtest.sce b/modules/graphics/demos/bezier/bezier3dtest.sce new file mode 100755 index 000000000..8d2c2bd6a --- /dev/null +++ b/modules/graphics/demos/bezier/bezier3dtest.sce @@ -0,0 +1,21 @@ +// +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) INRIA +// +// This file is distributed under the same license as the Scilab package. +// + +// Show a Beziercurve of dimension 3 + +function bezier3dtest () + my_handle = scf(100001); + clf(my_handle,"reset"); + + p=[-1,-1,-1;0,-1,-1;1,0,0;1,1,0;0,1,1;-1,1,0]' + bezier3d(p); + + demo_viewCode("bezier3dtest.sce"); +endfunction + +bezier3dtest(); +clear bezier3dtest; diff --git a/modules/graphics/demos/bezier/beziersurftest.sce b/modules/graphics/demos/bezier/beziersurftest.sce new file mode 100755 index 000000000..6ec8ac9b0 --- /dev/null +++ b/modules/graphics/demos/bezier/beziersurftest.sce @@ -0,0 +1,33 @@ +// +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) INRIA +// +// This file is distributed under the same license as the Scilab package. +// + +// Show a Bezier surface + +function beziersurftest + + x=linspace(-%pi,%pi,5); + [x,y]=field(x,x); + z= 3*sin(x).*cos(y); + [xb,yb,zb]=beziersurface(x,y,z); + + my_handle = scf(100001); + clf(my_handle,"reset"); + + subplot(2,1,1); + drawlater(); + plot3d3(x,y,z); + title("A first surface","fontsize",3); + subplot(2,1,2); + plot3d2(xb,yb,zb,-1,35,45," ",[4,2,3]); + title("The bezier interpolated surface (n=10)","fontsize",3); + drawnow(); + demo_viewCode("beziersurftest.sce"); + +endfunction + +beziersurftest(); +clear beziersurftest; diff --git a/modules/graphics/demos/bezier/beziertest.sce b/modules/graphics/demos/bezier/beziertest.sce new file mode 100755 index 000000000..1becf853f --- /dev/null +++ b/modules/graphics/demos/bezier/beziertest.sce @@ -0,0 +1,30 @@ +// +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) INRIA +// +// This file is distributed under the same license as the Scilab package. +// + +// a random polygon and a bezier curve + +function beziertest + + my_handle = scf(100001); + clf(my_handle,"reset"); + + plot2d(-0.2,-0.2,0,"011"," ",[-0.2,-0.2,1.2,1.2]); + title("Bezier Test : random polygon and bezier curve","fontsize",3); + rand("uniform"); + p = rand(2,5); + t = linspace(0,1,300); + s = bezier(p,t); + + plot2d(p(1,:),p(2,:),1); + plot2d(s(1,:),s(2,:),2); + + demo_viewCode("beziertest.sce"); + +endfunction + +beziertest(); +clear beziertest; diff --git a/modules/graphics/demos/bezier/c1test.sce b/modules/graphics/demos/bezier/c1test.sce new file mode 100755 index 000000000..e786aa150 --- /dev/null +++ b/modules/graphics/demos/bezier/c1test.sce @@ -0,0 +1,61 @@ +// +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) INRIA +// +// This file is distributed under the same license as the Scilab package. +// + +// Show how two bezier surfaces can be joined. + +function c1test() + + // first surface' + x1=dup(-0.5:0.25:0.5,5); + y1=dup([0,0,0,0,1],5); + z1=dup(2:0.25:3,5)'; + [xb1,yb1,zb1]=beziersurface(x1,y1,z1,10); + + // second surface + x2=dup(-0.5:0.25:0.5,5); + y2=[(ones(4,5));[0,0,0,0,0]]; + z2=-dup(-1:0.25:0,5)'; + [xb2,yb2,zb2]=beziersurface(x2,y2,z2,10); + + // a surface to link the two previous ones' + x=zeros(5,5); y=x; z=x; + x(1,:)=x1(1,:); x(2,:)=x(1,:)-(x1(2,:)-x1(1,:)); + x(5,:)=x2(1,:); x(4,:)=x(5,:)-(x2(2,:)-x2(1,:)); + x(3,:)=(x(4,:)+x(2,:))/2; + y(1,:)=y1(1,:); y(2,:)=y(1,:)-(y1(2,:)-y1(1,:)); + y(5,:)=y2(1,:); y(4,:)=y(5,:)-(y2(2,:)-y2(1,:)); + y(3,:)=(y(4,:)+y(2,:))/2; + z(1,:)=z1(1,:); z(2,:)=z(1,:)-(z1(2,:)-z1(1,:)); + z(5,:)=z2(1,:); z(4,:)=z(5,:)-(z2(2,:)-z2(1,:)); + z(3,:)=(z(4,:)+z(2,:))/2; + A=35,T=50,L=" ",EB=[4,2,0]; + [xb,yb,zb]=beziersurface(x,y,z,10); + + //drawing + my_handle = scf(100001); + clf(my_handle,"reset"); + my_current_axis = gca(); + drawlater(); + subplot(2,1,1); + title("how two bezier surfaces can be joined","fontsize",3); + subplot(2,2,1); + plot3d2(xb1,yb1,zb1,-1,A,T,L,EB); + subplot(2,2,3); + plot3d2(xb2,yb2,zb2,-1,A,T,L,EB); + subplot(1,2,2); + [n1,p1]=size(xb1); + [n2,p2]=size(xb); + plot3d2([xb1;xb;xb2],[yb1;yb;yb2],[zb1;zb;zb2],-1,A,T,L,EB); + delete(my_current_axis); + drawnow(); + + demo_viewCode("c1test.sce"); + +endfunction + +c1test(); +clear c1test; diff --git a/modules/graphics/demos/bezier/gammatest.sce b/modules/graphics/demos/bezier/gammatest.sce new file mode 100755 index 000000000..ba26992d7 --- /dev/null +++ b/modules/graphics/demos/bezier/gammatest.sce @@ -0,0 +1,42 @@ +// +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) INRIA +// +// This file is distributed under the same license as the Scilab package. +// + +// Bezier curve approximating a circle + +function gammatest (N) + + [lhs,rhs] =argn(0); + + if rhs < 1 then + N=[10,20,50,100]; + end + + x = linspace(0,1,100); + + my_handle = scf(100001); + clf(my_handle,"reset"); + + plot2d(cos(2*%pi*x),sin(2*%pi*x)); + ax = gca(); + ax.isoview = "on"; + title("Bezier curve approximating a circle","fontsize",3); + icol=2; + + for n=N ; + t = sqrt(linspace(0,1,n)); + p = [cos(2*%pi*t);sin(2*%pi*t)]; + y = bezier(p,x); + plot2d(y(1,:),y(2,:),icol); + icol=icol+1; + end + + demo_viewCode("gammatest.sce"); + +endfunction + +gammatest(); +clear gammatest; |