# 求Hermite曲线算法

fatcatman 2004-05-06 09:24:01

...全文
792 13 打赏 收藏 举报

13 条回复

liushuaiboy 2004-05-06

• 打赏
• 举报

Johnnyxy 2004-05-06

• 打赏
• 举报

fatcatman 2004-05-06
• 打赏
• 举报

fatcatman 2004-05-06
• 打赏
• 举报

freefalcon 2004-05-06

• 打赏
• 举报

fatcatman 2004-05-06

• 打赏
• 举报

fatcatman 2004-05-06

#define Iterative 24 /* 曲线仿真的线数(必须小于32) */
#define Iterative2 (Iterative*Iterative)
#define Iterative3 (Iterative2*Iterative)

void DrawHermiteCurve(int x1,int y1,int x2,int y2,int xr1,int yr1,
int xr2,int yr2)
{
/* ------------------------------------------------------------

xr1,yr1,xr2,yr2 = 曲线两参考向量

------------------------------------------------------------ */
int i, oldx, oldy, m1, m2, m3, m4, x, y, k1, k2;

oldx = x1;
oldy = y1;
m1 = Iterative3;
m2 = m3 = m4 = 0;
for (i=0; i<Iterative; i++) /* 用Iterative条直线仿真 */
{
k1 = (i << 1) + 1;
k2 = (k1+i)*i + k1;
m4 += (k2 -= (k1 *= Iterative));
m3 += (k1 = k2 - k1) + Iterative2;
m2 -= (k2 += k1);
m1 += k2;
x = (int) (((long) x1*m1 + (long) x2*m2 + (long) xr1*m3 +
(long) xr2*m4) / Iterative3);
y = (int) (((long) y1*m1 + (long) y2*m2 + (long) yr1*m3 +
(long) yr2*m4) / Iterative3);
DrawLine(oldx,oldy,x,y);
oldx = x;
oldy = y;
}
}

void DrawBezierCurve(int x1,int y1,int x2,int y2,int xr1,int yr1,
int xr2,int yr2)
{
/* ------------------------------------------------------------

xr1,yr1,xr2,yr2 = 曲线两参考点

------------------------------------------------------------ */
DrawHermiteCurve(x1,y1,x2,y2,3*(xr1-x1),3*(yr1-y1),3*(x2-xr2),3*(y2-yr2));
}
• 打赏
• 举报

junnyfeng 2004-05-06

• 打赏
• 举报

fatcatman 2004-05-06

• 打赏
• 举报

freefalcon 2004-05-06

• 打赏
• 举报

happyasen 2004-05-06

From: Chi'u I-Nan * Area: 90 C 语言
To: All Date: 03 May 95 22:37:26
Subj: Hermite 与 Bezier 曲线的绘制

**********************************************************************
* Hermite与Bezier曲线绘制方法研究 *
* 作者：邱奕南 (Chi'u I-Nan) *
* 版权声明：以下文章内容本人仅同意供BBS 站上流传学习，但必须完整流传 *
* （含版权声明及程序），其余权利一概保留。任何未经本人同意 *
* ，将本文贩卖、刊登、节录、或其它一切侵害本人著作权之行为 *
* 者，皆需负担刑事责任及民事赔偿责任。 *
**********************************************************************

Hermite及Bezier曲线为三度空间曲线的常用表示法，以下我们先说明一

1.Hermite曲线

Hermite曲线为给定两端点及两端点向量所得的三次曲线。令三次曲线：

3 2
x(t) = Ax * t + Bx * t + Cx * t + d

3 2
y(t) = Ay * t + By * t + Cy * t + d

x(0) = x1, y(0) = y1
x(1) = x2, y(1) = y2
x'(0) = xr1, y'(0) = yr1
x'(1) = xr2, y'(1) = yr2

2.Bezier曲线

Bezier曲线为给定两端点及另两参考点所得的三次曲线，它可说是Hermite

Bezier曲线换算成Hermite曲线的方式为：

R1 = 3*(Pr1-P1)
R2 = 3*(P2-Pr2)

R1、R2即为Hermite曲线的两端点向量。

Hermite曲线为主。由Hermite曲线的定义，首先我们必须求出Ax,Bx...等值。

x(0) = x1, x(1) = x2, x'(0) = xr1, x'(1) = xr2

2
x'(t) = 3 * Ax * t + 2 * Bx * t + Cx

┌ 0 0 0 1 ┐┌ Ax ┐ ┌ x1 ┐
│ 1 1 1 1 ││ Bx │＝│ x2 │
│ 0 0 1 0 ││ Cx │ │ xr1 │
└ 3 2 1 0 ┘└ Dx ┘ └ xr2 ┘

┌ Ax ┐ ┌ 2 -2 1 1 ┐┌ x1 ┐
│ Bx │＝│ -3 3 -2 1 ││ x2 │
│ Cx │ │ 0 0 1 0 ││ xr1 │
└ Dx ┘ └ 1 0 0 0 ┘└ xr2 ┘

x(t) = (2*t^3 - 3*t^2 + 1) * x1 + (-2*t^3 + 3*t^2) * x2 +
(t^3 - 2*t^2 + t) * xr1 + (t^3 - t^2) * xr2

y(t) = (2*t^3 - 3*t^2 + 1) * y1 + (-2*t^3 + 3*t^2) * y2 +
(t^3 - 2*t^2 + t) * yr1 + (t^3 - t^2) * yr2

x(i) = (m1*x1 + m2*x2 + m3*xr1 + m4*xr2) / n^3
y(i) = (m1*y1 + m2*y2 + m3*yr1 + m4*yr2) / n^3

m1 = 2*i^3 - 3*n*i^2 + n^3 , 0 <= i <= n
m2 = -2*i^3 + 3*n*i^2
m3 = i^3 - 2*n*i^2 + n^2*i
m4 = i^3 - n*i^2

3次移位乘法和7次加法），在计算上仍然会浪费相当多时间（PC上的乘法约为

m1(i+1) = m1(i) + 6*i^2 + 6*i + 2 - 3*n*(2*i+1)
m2(i+1) = m2(i) - 6*i^2 - 6*i - 2 + 3*n*(2*i+1)
m3(i+1) = m3(i) + 3*i^2 + 3*i + 1 - 2*n*(2i+1) + n^2
m4(i+1) = m4(i) + 3*i^2 + 3*i + 1 - n*(2*i+1)

m1(i+1) = m1(i) + a
m2(i+1) = m2(i) - a
m3(i+1) = m3(i) + d - c + n^2
m4(i+1) = m4(i) + d
a = 2*b - 3*c
b = 3*i^2 + 3*i + 1
c = n*(2*i+1)
d = b-c

e = 2*i + 1
c = n*e
b = 3*i^2 + 3*i + 1
= (3*i+1)*i + (2*i+1)
= (e+i)*i + e

e = 2*i + 1
b = (e+i)*i + e
c = n*e
d = b-c
m4 = m4 + d
f = d-c
m3 = m3 + f + n^2
a = d + f
m2 = m2 - a
m1 = m1 + a

m1(0) = n^3
m2(0) = m3(0) = m4(0) = 0

#define Iterative 24 /* 曲线仿真的线数(必须小于32) */
#define Iterative2 (Iterative*Iterative)
#define Iterative3 (Iterative2*Iterative)

void DrawHermiteCurve(int x1,int y1,int x2,int y2,int xr1,int yr1,
int xr2,int yr2)
{
/* ------------------------------------------------------------

xr1,yr1,xr2,yr2 = 曲线两参考向量

------------------------------------------------------------ */
int i, oldx, oldy, m1, m2, m3, m4, x, y, k1, k2;

oldx = x1;
oldy = y1;
m1 = Iterative3;
m2 = m3 = m4 = 0;
for (i=0; i<Iterative; i++) /* 用Iterative条直线仿真 */
{
k1 = (i << 1) + 1;
k2 = (k1+i)*i + k1;
m4 += (k2 -= (k1 *= Iterative));
m3 += (k1 = k2 - k1) + Iterative2;
m2 -= (k2 += k1);
m1 += k2;
x = (int) (((long) x1*m1 + (long) x2*m2 + (long) xr1*m3 +
(long) xr2*m4) / Iterative3);
y = (int) (((long) y1*m1 + (long) y2*m2 + (long) yr1*m3 +
(long) yr2*m4) / Iterative3);
DrawLine(oldx,oldy,x,y);
oldx = x;
oldy = y;
}
}

void DrawBezierCurve(int x1,int y1,int x2,int y2,int xr1,int yr1,
int xr2,int yr2)
{
/* ------------------------------------------------------------

xr1,yr1,xr2,yr2 = 曲线两参考点

------------------------------------------------------------ */
DrawHermiteCurve(x1,y1,x2,y2,3*(xr1-x1),3*(yr1-y1),3*(x2-xr2),3*(y2-yr2));
}

＊ 青衫诗客 -- 小邱 ＊

-- Via 中文银版快信 V2.28C
! Origin: 档案货柜, 欢迎您来挖宝, ２８８００ BPS, 04-230-2080; (90:2010/622)
________________________________________
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
≡ 何陋居 ≡ 中学生以伏案读书为主, 大学生则应起而高瞻远瞩。 Whitehead.
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
• 打赏
• 举报

freefalcon 2004-05-06
http://bbs.ee.ntu.edu.tw/boards/Programming/14/7.html

1.HermiteΡ絬

HermiteΡ絬倒﹚ㄢ狠翴のㄢ狠翴秖┮眔ΩΡ絬ΩΡ絬

3 2
x(t) = Ax * t + Bx * t + Cx * t + d

3 2
y(t) = Ay * t + By * t + Cy * t + d

倒﹚ㄢ狠翴(x1,y1)(x2,y2)のㄢ狠翴秖(xr1,yr1)(xr2,yr2)

x(0) = x1, y(0) = y1
x(1) = x2, y(1) = y2
x'(0) = xr1, y'(0) = yr1
x'(1) = xr2, y'(1) = yr2

#define Iterative 24 /* Ρ絬家览絬计(ゲ斗32) */
#define Iterative2 (Iterative*Iterative)
#define Iterative3 (Iterative2*Iterative)

void DrawHermiteCurve(int x1,int y1,int x2,int y2,int xr1,int yr1,
int xr2,int yr2)
{
/* ------------------------------------------------------------
ノ礶HermiteΡ絬

xr1,yr1,xr2,yr2 = Ρ絬ㄢ把σ秖
玭 Chi'u I-Nan
------------------------------------------------------------ */
int i, oldx, oldy, m1, m2, m3, m4, x, y, k1, k2;

oldx = x1;
oldy = y1;
m1 = Iterative3;
m2 = m3 = m4 = 0;
for (i=0; i<Iterative; i++) /* ノIterative兵絬家览 */
{
k1 = (i << 1) + 1;
k2 = (k1+i)*i + k1;
m4 += (k2 -= (k1 *= Iterative));
m3 += (k1 = k2 - k1) + Iterative2;
m2 -= (k2 += k1);
m1 += k2;
x = (int) (((long) x1*m1 + (long) x2*m2 + (long) xr1*m3 +
(long) xr2*m4) / Iterative3);
y = (int) (((long) y1*m1 + (long) y2*m2 + (long) yr1*m3 +
(long) yr2*m4) / Iterative3);
DrawLine(oldx,oldy,x,y);
oldx = x;
oldy = y;
}
}
• 打赏
• 举报

fatcatman 2004-05-06

• 打赏
• 举报

C语言

6.6w+

C语言相关问题讨论

2004-05-06 09:24