贝塞罗曲线

给定点P0,P1,线性贝兹曲线是这两点之间连线的点,方程式如下:

B(t) = P0 + (P1 - P0)t t取[0,1];


假设P0(x0, y0),P1(x1, y1), Pn((1-t)x0+tx1),(1-t)y0+ty1)

1)通过点在直线上,斜率相等证明一阶贝塞罗曲线是一直线

K(PnP0) = K(PnP1)这种方法相对简单

2)通过P0P1两点根据点斜式求出直线的方程,然后将Pn点代入,

同样可以证明,相对繁琐


void myDisplay()

{

  glClear(GL_COLOR_BUFFER_BIT);

  glColor3f(1.0f,0.f,0.f);

  int P1x = 10;

  int P1y = 10;

  int P2x = 200;

  int P2y = 400;

  glPointSize(3);

  glLineWidth(1);

  glBegin(GL_POINTS);

  glVertex2d(P1x, P1y);

  glVertex2d(P2x, P2y);

  for (int i=0; i<10; i++)

  {

    double t = i*0.1;

    double x = (1-t)*P1x + t* P2x;

    double y = (1-t)*P1y + t* P2y;

    glVertex2d(x, y);

  }

  glEnd();

  glColor3f(0.f,1.f,0.f);

  glBegin(GL_LINES);

  glVertex2d(P1x, P1y);

  glVertex2d(P2x, P2y);

  glEnd();

  glFlush();

}


二次方公式

二次方贝兹曲线的路径由给定点P0、P1、P2的函数B(t):

B(t) = (1-t)*(1-t)P0 + 2*t*(1-t)P1 + t*tP2 t取[0,1];


#include <windows.h>

#include <gl/gl.h>

#include <gl/glu.h>

#include <gl/glut.h>


//

void myInit()

{

  glClearColor(1.0,1.0,1.0,0.0);

  glLineWidth(3.0);

  glMatrixMode(GL_PROJECTION);

  glLoadIdentity();

  gluOrtho2D(0.0,640,0.0,480);

}

/

void myDisplay()

{

  glClear(GL_COLOR_BUFFER_BIT);

  glColor3f(1.0f,0.f,0.f);

  int P1x = 10;

  int P1y = 10;

  int P2x = 200;

  int P2y = 400;

  int Pcx = 0;

  int Pcy = 200;

  glPointSize(3);

  glLineWidth(1);

  glBegin(GL_POINTS);

  glVertex2d(P1x, P1y);

  glVertex2d(P2x, P2y);

  glVertex2d(Pcx, Pcy);

  for (int i=0; i<100; i++)

  {

    double t = i*0.01;

    double x = (1-t)*(1-t)*P1x + 2*(1-t)*Pcx + t*t*P2x;

    double y = (1-t)*(1-t)*P1y + 2*(1-t)*Pcy + t*t*P2y;

    glVertex2d(x, y);

  }

  glEnd();

  glColor3f(0.f,1.f,0.f);

  glBegin(GL_LINES);

  glVertex2d(P1x, P1y);

  glVertex2d(P2x, P2y);

  glEnd();

  glFlush();

}

///

void main(int argc,char **argv)

{

  glutInit(&argc,argv);

  glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);

  glutInitWindowSize(640,480);

  glutInitWindowPosition(100,150);

  glutCreateWindow("example");

  glutDisplayFunc(myDisplay);

  myInit();

  glutMainLoop();

}




     本文转自fengyuzaitu 51CTO博客,原文链接:http://blog.51cto.com/fengyuzaitu/1379629,如需转载请自行联系原作者

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值