样条之埃尔米特(Hermite)

      埃尔米特(Charles Hermite,1822—1901) 法国数学家。巴黎综合工科学校毕业。曾任法兰西学院、巴黎高等师范学校、巴黎大学教授。法兰西科学院院士。在函数论、高等代数、微分方程等方面都有重要发现。1858年利用椭圆函数首先得出五次方程的解。1873年证明了自然对数的底e的超越性。在现代数学各分支中以他姓氏命名的概念(表示某种对称性)很多,如“埃尔米特二次型”、“埃尔米特算子”等。

  这种算法是由上一节讲的CatmullRom演变而成。

关于插值与样条的介绍请看:http://www.cnblogs.com/WhyEngine/p/4020294.html

核心代码:

 1 void    YcHermiteSpline::BuildWeights()
 2 {
 3     ClearWeights();
 4 
 5     for (Yuint i = 0; i < 4; i++)
 6     {
 7         m_splineWeights[i] = (Yreal*)malloc((m_subD)*sizeof(Yreal));
 8     }
 9 
10     Yreal u, u_2, u_3;
11     for (Yuint i = 0; i < m_subD; i++)
12     {
13         u = (float)i / m_subD;
14         u_2 = u * u;
15         u_3 = u_2 * u;
16 
17         // 参见"游戏编程精粹1"P420
18         /*
19         m0 = ((1 - alpha) / 2.0f) * ((v2 - v1) + v3 - v2);
20         m1 = ((1 - alpha) / 2.0f) * ((v3 - v2) + v4 - v3);
21 
22         dest = (((2 * t3) - (3 * t2) + 1) * v2) +
23                 ((t3 - (2 * t2) + t) * m0) +
24                 ((t3 - t2) * m1) +
25                 (((-2 * t3) + (3 * t2)) * v3);
26 
27         ====================
28 
29         m0 = ((1 - alpha) / 2.0f) * (v3 - v1);
30         m1 = ((1 - alpha) / 2.0f) * (v4 - v2);
31 
32         m0 = ((1 - alpha) / 2.0f) * v3 - ((1 - alpha) / 2.0f) * v1;
33         m1 = ((1 - alpha) / 2.0f) * v4 - ((1 - alpha) / 2.0f) * v2;
34 
35         ====================
36 
37         dest = (((2 * t3) - (3 * t2) + 1) * v2) +
38                 ((t3 - (2 * t2) + t) * ((1 - alpha) / 2.0f) * v3) 
39                -((t3 - (2 * t2) + t) * ((1 - alpha) / 2.0f) * v1) 
40                 ((t3 - t2) * ((1 - alpha) / 2.0f) * v4) 
41                -((t3 - t2) * ((1 - alpha) / 2.0f) * v2) 
42                 (((-2 * t3) + (3 * t2)) * v3);
43 
44         ====================
45 
46         v1: -((t3 - (2 * t2) + t) * ((1 - alpha) / 2.0f)
47         v2: ((2 * t3) - (3 * t2) + 1) - (t3 - t2) * ((1 - alpha) / 2.0f)
48         v3: (t3 - (2 * t2) + t) * ((1 - alpha) / 2.0f) + ((-2 * t3) + (3 * t2))
49         v4: (t3 - t2) * ((1 - alpha) / 2.0f)
50         */
51 
52         // CatmullRom
53         // 貌似m_alpha==0时,Hermite就是CatmullRom
54         //m_splineWeights[0][i] = (-1.0f*u_3 + 2.0f*u_2 - 1.0f*u + 0.0f)*0.5f;
55         //m_splineWeights[1][i] = ( 3.0f*u_3 - 5.0f*u_2 + 0.0f*u + 2.0f)*0.5f;
56         //m_splineWeights[2][i] = (-3.0f*u_3 + 4.0f*u_2 + 1.0f*u + 0.0f)*0.5f;
57         //m_splineWeights[3][i] = ( 1.0f*u_3 - 1.0f*u_2 + 0.0f*u + 0.0f)*0.5f;
58 
59         m_splineWeights[0][i] = -(u_3 - (2 * u_2) + u) * (1 - m_alpha) / 2.0f;
60         m_splineWeights[1][i] = (2 * u_3) - (3 * u_2) + 1 - (u_3 - u_2) * (1 - m_alpha) / 2.0f;
61         m_splineWeights[2][i] = (-2 * u_3) + (3 * u_2) + (u_3 - (2 * u_2) + u) * (1 - m_alpha) / 2.0f;
62         m_splineWeights[3][i] = (u_3 - u_2) * (1 - m_alpha) / 2.0f;
63     }
64 }

切图:

 

 

相关软件的下载地址为:https://files.cnblogs.com/WhyEngine/TestSpline.zip

posted on 2014-10-15 06:50  叶飞影  阅读(4592)  评论(0编辑  收藏  举报