在OpenGL中绘制Hermite曲线 [英] Drawing Hermite curves in OpenGL

查看:332
本文介绍了在OpenGL中绘制Hermite曲线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用OpenGL绘制Hermite曲线,是否有任何内置函数?我在网上看到了一些示例,这些示例显示了如何使用评估器绘制Bezier曲线,但找不到有关Hermite曲线的任何信息.

How can I draw Hermite curves using OpenGL, are there any built in functions? I saw some examples on-line that show how to use evaluators to draw Bezier curves but could not find any information for Hermite curves.

推荐答案

让Bezier的控制点矢量为[b0 b1 b2 b3],而Hermite的控制点矢量为[h0 h1 v0 v1](v0和v1为在点h0和h1处的导数/切线).然后,我们可以使用矩阵形式来显示转换:

Let the vector of control points for your Bezier be [b0 b1 b2 b3] and those for your Hermite be [h0 h1 v0 v1] (v0 and v1 being the derivative / tangent at points h0 and h1). Then we can use a matrix form to show the conversions:

赫尔米特石成贝塞尔曲线

Hermite to Bezier


[b0] = 1 [ 3  0  0  0] [h0]
[b1]   - [ 3  0  1  0] [h1]
[b2]   3 [ 0  3  0 -1] [v0]
[b3]     [ 0  3  0  0] [v1]

(与上述纳夫的回答完全相同).

(this is exactly as in Naaff's response, above).

贝济耶到埃尔米特


[h0] = [ 1  0  0  0] [b0]
[h1]   [ 0  0  0  1] [b1]
[v0]   [-3  3  0  0] [b2]
[v1]   [ 0  0 -3  3] [b3]

因此,在矩阵形式下,这些可能比所需的要复杂一些(在所有Naaff的代码都简短到此为止).这很有用,因为我们现在可以非常轻松地超越隐士.

So in matrix form these are perhaps slightly more complex than needed (after all Naaff's code was short and to the point). It is useful, because we can go beyond Hermites very easily now.

尤其是,我们可以引入另一个经典的基数三次参数曲线:Catmull-Rom曲线.它具有控制点[c_1 c0 c1 c2](与Bezier曲线不同,该曲线从第二个控制点到第三个控制点,因此习惯编号从-1开始).然后,转换为Bezier:

In particular we can bring in the other classic cardinal cubic parametric curve: the Catmull-Rom curve. It has control points [c_1 c0 c1 c2] (unlike Bezier curves, the curve runs from the second to the third control point, hence the customary numbering from -1). The conversions to Bezier are then:

卡特姆-罗姆到贝济耶


[b0] = 1 [ 0  6  0  0] [c_1]
[b1]   - [-1  6  1  0] [c0]
[b2]   6 [ 0  1  6 -1] [c1]
[b3]     [ 0  0  6  0] [c2]

贝济耶飞往Catmull-Rom

Bezier to Catmull-Rom


[c_1] = [ 6 -6  0  1] [b0]
[c0]    [ 1  0  0  0] [b1]
[c1]    [ 0  0  0  1] [b2]
[c2]    [ 1  0 -6  6] [b3]

我也可以做Hermite到Catmull-Rom的配对,但是由于Bezier通常是主要的代表,所以很少使用它们.

I can do the Hermite to Catmull-Rom pair too, but they're rarely used, since Bezier is normally the primary representation.

这篇关于在OpenGL中绘制Hermite曲线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆