您好,欢迎访问三七文档
当前位置:首页 > 电子/通信 > 电子设计/PCB > de-Boor-Cox算法的-Turbo-C-2.0程序
/*1¡¢¸ø¶¨Æ½ÃæÉÏ15¸ö²»Í¬µÄµã£¬ÓÃdeBoor_CoxËã·¨±à³ÌÉú³ÉƽÃæÈý´ÎBÑùÌõÇúÏß¡£*/#includegraphics.h#includestdlib.h#includestdio.hvoidbsp1_to_points(intdegree,intL,floatcoeff[],floatknot[],intdense,floatpoints[]);floatdeboor(intdegree,floatcoeff[],floatknot[],floatu,inti);voidmain(){floatXcoeff[15];/*={20,60,100,140,180,220,260,300,340,380,420,460,500,540,580};*/floatYcoeff[15];/*={450,400,350,300,250,200,150,100,150,200,250,300,350,400,450};*/floatXpoints[1100],Ypoints[1100];/*ÇúÏßÉϵã×ÜÊýÁ¿=L*dense*/intdegree,L,dense,n,m,T;intknot[16]={0,0,1,2,3,4,5,6,7,8,9,10,11,12,12,12};/*¶ÔÓÚL=11,degree=3µÄ¾ùÔÈ·ÇÖÜÆÚ½ÚµãʸÁ¿*/intdrive=VGA,mode=VGAHI;n=14;/*¿ØÖƵãÊýn+1=15*/degree=3;/*ÇúÏß´ÎÊýdegree*/L=n-degree;/*ÇúÏß·Ö¶ÎÊýL=*/dense=100;/*ÿ¶ÎÇúÏßÉú³ÉµãÊýÁ¿dense*/initgraph(&drive,&mode,C:\\TC20\\BGI);setcolor(15);setbkcolor(0);/*Ëæ»ú²úÉú15¸ö¿ØÖƵã×ø±ê£¬ÓÃÐéÏßÁ¬½Ó*/printf(Inputainteger(1~30000)togeneratearandomcubicB-spline:\n);scanf(%d,&T);setlinestyle(3,1,1);for(m=0;m15;m++){Xcoeff[m]=(float)random(T+1)/T*640;Ycoeff[m]=(float)random(T+1)/T*480;circle(Xcoeff[m],Ycoeff[m],2);if(m0){line(Xcoeff[m-1],Ycoeff[m-1],Xcoeff[m],Ycoeff[m]);}}/*¼ÆËãÇúÏßÉϵ㣬ÓÃÖ±ÏßÁ¬½Ó*/setlinestyle(0,1,1);bsp1_to_points(degree,L,Xcoeff,knot,dense,Xpoints);bsp1_to_points(degree,L,Ycoeff,knot,dense,Ypoints);setcolor(12);for(m=0;mL*dense;m++){if(m0)line(Xpoints[m-1],Ypoints[m-1],Xpoints[m],Ypoints[m]);}setcolor(15);getch();}voidbsp1_to_points(intdegree,intL,floatcoeff[],floatknot[],intdense,floatpoints[]){inti,ii;floatu=0;intpoint_num=0;for(i=degree-1;iL+degree-1;i++){if(knot[i+1]knot[i]){for(ii=0;iidense;ii++){u=knot[i]+ii*(knot[i+1]-knot[i])/dense;points[point_num]=deboor(degree,coeff,knot,u,i);point_num++;}}}}floatdeboor(intdegree,floatcoeff[],floatknot[],floatu,inti){intk,j;floatt1,t2;floatcoeffa[30];for(j=i-degree+1;j=i+1;j++)coeffa[j]=coeff[j];for(k=1;k=degree;k++){for(j=i+1;j=i-degree+k+1;--j){t1=(knot[j+degree-k]-u)/(knot[j+degree-k]-knot[j-1]);t2=1.0-t1;coeffa[j]=t1*coeffa[j-1]+t2*coeffa[j];}}return(coeffa[i+1]);}
本文标题:de-Boor-Cox算法的-Turbo-C-2.0程序
链接地址:https://www.777doc.com/doc-7230535 .html