bezier曲线的插值模拟算法

/***********************************************************************
REVISION LOG ENTRY
Revision By: http://blog.csdn.net/hongweijin
Revised on : 2004-10-22 5:34:30
Comments : bezier二次曲线的插值模拟算法***********************************************************************/

#include "stdio.h"
#include "stdlib.h"

void main( void )
{
inti;
doublet;
doublex;

/*P0是一个顶点,P1是第三点确定的,P2是第二点确定的*/
float P0[2], P1[2], P2[2];

printf("输入第一点的坐标X:");
scanf("%f", &P0[0]);
printf("输入第一点的坐标Y:");
scanf("%f", &P0[1]);
printf("\n输入第二点的坐标X:");
scanf("%f", &P1[0]);
printf("输入第二点的坐标Y:");
scanf("%f", &P1[1]);
printf("\n输入第三点的坐标X:");
scanf("%f", &P2[0]);
printf("输入第三点的坐标Y:");
scanf("%f", &P2[1]);

for(i = 0; i < 10000; i++)
{
t = i / 10000.0;

x = (1-t) * (1-t) * P0[0] + (2*t) * (1-t) * P1[0] + t*t*P2[0];
printf("%f,", x);
x = (1-t) * (1-t) * P0[1] + (2*t) * (1-t) * P1[1] + t*t*P2[1];
printf("%f\n", x);

}
}





/***********************************************************************
REVISION LOG ENTRY
Revision By:
http://blog.csdn.net/hongweijin
Revised on : 2004-10-22 5:34:30
Comments : bezier三次曲线的插值模拟算法
***********************************************************************/

#include "stdio.h"
#include "stdlib.h"

void main( void )
{
inti;
doublet;
doublex;

/*P0是一个顶点,P1是第三点确定的,P2是第二点确定的*/
float P0[2], P1[2], P2[2], P3[2];

printf("输入第一点的坐标X:");
scanf("%f", &P0[0]);
printf("输入第一点的坐标Y:");
scanf("%f", &P0[1]);
printf("\n输入第二点的坐标X:");
scanf("%f", &P1[0]);
printf("输入第二点的坐标Y:");
scanf("%f", &P1[1]);
printf("\n输入第三点的坐标X:");
scanf("%f", &P2[0]);
printf("输入第三点的坐标Y:");
scanf("%f", &P2[1]);
printf("\n输入第四点的坐标X:");
scanf("%f", &P3[0]);
printf("输入第四点的坐标Y:");
scanf("%f", &P3[1]);

for(i = 0; i < 100; i++)
{
t = i / 100.0;

x = (1-t)*(1-t)*(1-t)*P0[0]+(3*t)*(1-t)*(1-t)*P1[0]+3*t*t*(1-t)*P2[0]+t*t*t*P3[0];
printf("%f,", x);
x = (1-t)*(1-t)*(1-t)*P0[1]+(3*t)*(1-t)*(1-t)*P1[1]+3*t*t*(1-t)*P2[1]+t*t*t*P3[1];
printf("%f\n", x);

}
}




在TC3.0环境下用二次插值画的曲线:

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>

int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
inti;
doublet;
int x;
int y;
int P0[2] = {1, 1}, P1[2] = {50, 50}, P2[2]={70, 1};

/* initialize graphics mode */
initgraph(&gdriver, &gmode, "c:/tc");

/* read result of initialization */
errorcode = graphresult();

if (errorcode != grOk) /* an error occurred */
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* return with error code */
}

for(i = 0; i < 1000; i++)
{
t = i / 1000.0;

x =125 + 5* ((1-t) * (1-t) * P0[0] + (2*t) * (1-t) * P1[0] + t*t*P2[0]);

y =120 + 5*((1-t) * (1-t) * P0[1] + (2*t) * (1-t) * P1[1] + t*t*P2[1]);
/* if ((x == (102 + 5) && y == (120 + 5)) ||(x == (102 + 5*15) && y == (120 + 5))||(x == (102 + 5) && y == (120 + 5)) )
*/
putpixel( x, y, 4);
putpixel(125 + 5*P0[1], 120 + 5 * P0[1] ,2);
putpixel(125 + 5*P1[0], 120 + 5 * P1[1], 2);
putpixel(125 + 5*P2[0], 120 + 5 * P2[1] , 2);

}

/* clean up */
getch();
closegraph();
return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值