Bezier曲线:

<!-- /* Font Definitions */ @font-face {font-family:宋体; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:SimSun; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} @font-face {font-family:"/@宋体"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; mso-pagination:none; font-size:10.5pt; mso-bidi-font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:宋体; mso-font-kerning:1.0pt;} /* Page Definitions */ @page {mso-page-border-surround-header:no; mso-page-border-surround-footer:no;} @page Section1 {size:612.0pt 792.0pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:36.0pt; mso-footer-margin:36.0pt; mso-paper-source:0;} div.Section1 {page:Section1;} -->


#include <glut.h>

#include "math.h"

#include <stdio.h>

void init(void)

{

       glClearColor(0.0,0.15,0.0,0.0);

       glMatrixMode(GL_PROJECTION);

       gluOrtho2D(0.0,600.0,  0.0,450.0);

}

double my_pow(double u,int i)

{

       double sum=1;;

       for (int j=1;j<=i;j++)

       {

              sum*=u;

       }

       return sum;

}

void DDAline(int x0 , int y0 , int x1 , int y1)

{

       if(x0>x1)

       {     

              x0+=x1,x1=x0-x1,x0-=x1;

              y0+=y1,y1=y0-y1,y0-=y1;

       }//swap start point & end point

       int i;

       if(y0==y1)

       {

              for (i=x0; i<=x1; i++)

                     glVertex2i(i, y0);

              return;

       }

       if(x0==x1)    

       {

              for (i=y0; i<=y1; i++)

                     glVertex2i(x0, i);

              return;

       }

       float x,y,delta_x,delta_y;

       int dy,dx,steps;

       dx =x1-x0;

       dy = y1-y0;

       if(abs(dx) > abs(dy))

       {          

              steps=abs(dx);

              delta_x=1;

              delta_y=(float)dy/(float)steps;

       }

       else

       {              

              steps=abs(dy);

              if (dy<0)

                     delta_y = -1;

              else

                     delta_y=1;

              delta_x=(float)dx/(float)steps;

       }

       x=x0, y=y0;

       glVertex2i(x,y);

       for (i=1; i<=steps; i++){

              x+=delta_x, y+=delta_y;

              glVertex2i((int)x,(int)y);

       }

}

double Caaa(int i,int n)

{

       int x=1;int y=1;int k;

       for ( k=i+1;k<=n;k++)

       {

              x*=k;

       }

       for (k=1;k<=n-i;k++ )

       {

              y*=k;

       }

       return (double)x/(double)y;

}

long   double Baaa(int i,int n,double u)

{

       return  Caaa(i,n)*(my_pow(u,i)*my_pow(1-u,n-i));

}

void Bezier()

{

       int x[]={10,160,310,510};

       int y[]={10,250,15,200};

       for (int z=0;z<3;z++)

       {

              DDAline(x[z],y[z],x[z+1],y[z+1]);

       }

       int n=4;

       int sumX=0;

       int sumY=0;

       double u=0.0;

       int i=0;

       for (u=0.0;u<=1.0;u+=0.01)

       {

              for (i=0;i<n;i++)

              {

                     sumX+=x[i]*Baaa(i,n-1,u);

                     sumY+=y[i]*Baaa(i,n-1,u);

              }

              glVertex2f(sumX,sumY);

              sumX=0;

              sumY=0;

       }

}

void DRAW(void)

{

       glClear(GL_COLOR_BUFFER_BIT);

       glColor3f(1.0,0.0,0.0);

       glBegin(GL_POINTS);

       Bezier();

       glEnd();

       glFlush();

}

void main(int argc,char** argv)

{

       glutInit(&argc,argv);

       glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);

       glutInitWindowPosition(400,300);//openGL 窗口的位置

       glutCreateWindow(" 图形学 four");

       init();

       glutDisplayFunc(DRAW);//Register callback function to display graphics.

       glutMainLoop();

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值