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);
}