查看单个帖子
旧 2008-10-27, 11:48 AM   #2
huangyhg
超级版主
 
huangyhg的头像
 
注册日期: 04-03
帖子: 18592
精华: 36
现金: 249466 标准币
资产: 1080358888 标准币
huangyhg 向着好的方向发展
默认 回复: 【转帖】请高手指点样条曲线的画法!!

8 楼askcsdn(千万次地问)回复于 2002-10-23 15:38:43 得分 100

没错,polybezier不是样条曲线而是贝塞尔曲线,确切来说样条曲线还分为:参数样条曲线和B样条曲线,autocad中画的应该是三次B样条曲线
用如下代码试试
int i,n;
n = 9;
double t,t2,t3,a0,a1,a2,a3,b0,b1,b2,b3,dt,xa,ya;
int x[4] = {103,140,219,350};//控制点x坐标
int y[4] = {111,135,188,57};//控制点y坐标
a0 = (x[0] + 4 * x[1] + x[2])/6;
a1 = -(x[0] - x[2])/2;
a2 = (x[2] - 2 * x[1] + x[0])/2;
a3 = -(x[0] - 3 * x[1] + 3 * x[2] - x[3])/6;
b0 = (y[0] + 4 * y[1] + y[2])/6;
b1 = -(y[0] - y[2])/2;
b2 = (y[2] - 2 * y[1] + y[0])/2;
b3 = -(y[0] - 3 * y[1] + 3 * y[2] - y[3])/6;
dt = 1.0/n;

for (i = 0; i <= n; i ++)
{
t = i * dt;
t2 = t * t;
t3 = t2 * t;
xa = a0 + a1 * t + a2 * t2 + a3 * t3;
ya = (b0 + b1 * t + b2 * t2 + b3 * t3);
if (i == 0)
pDC->MoveTo(xa,ya);
else
pDC->LineTo(xa,ya);
}
__________________
借用达朗贝尔的名言:前进吧,你会得到信心!
[url="http://www.dimcax.com"]几何尺寸与公差标准[/url]
huangyhg离线中   回复时引用此帖