计算机图形学上机实验(2)
#include<graphics.h>
#include<stdio.h>
#include<conio.h>
#dene num 5000
double pointx[4]={50,150,250,350};
double pointy[4]={50,150,250,160};
const int n=3;
double points[num+1][2];
double deCasteljgu(double a[],double t);
void Point()
{ double t=0.0;
for(int i=0;i<=num;i++)
{ points[i][0]=deCasteljgu(pointx,t);
points[i][1]=deCasteljgu(pointy,t);
t=t+1.0/(double)num;
}
}
double deCasteljgu(double x[],double t)
{
double P[n+1][n+1]={0};
for(int i=0;i<=n;i++) P[i][0]=x[i];
for(int k=1;k<=n;k++)
for(int i=0;i<=n-k;i++)
P[i][k]=(1.0-t)*P[i][k-1]+t*P[i+1][k-1];
return P[0][n];
}
void main()
{ initgraph(500,500);
Point();
for(int m=0;m<num;m++)
putpixel(points[m][0],points[m][1],WHITE);
getch();
}
评论0
最新资源