在OpenGL中绘制Hermite曲线

发布于 2024-07-24 14:21:46 字数 87 浏览 2 评论 0原文

如何使用 OpenGL 绘制 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

月隐月明月朦胧 2024-07-31 14:21:47

令贝塞尔曲线的控制点向量为 [b0 b1 b2 b3],埃尔米特曲线的控制点向量为 [h0 h1 v0 v1](v0 和 v1 是点 h0 和 h1 处的导数/切线)。 然后我们可以使用矩阵形式来显示转换:

Hermite 到 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]

(这与上面 Naaff 的响应完全相同)。

Bezier 到 Hermite

[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 的代码简短而切题)。 它很有用,因为我们现在可以很容易地超越隐士。

特别是,我们可以引入另一个经典的基数三次参数曲线:Catmull-Rom 曲线。 它有控制点 [c_1 c0 c1 c2](与贝塞尔曲线不同,该曲线从第二个控制点延伸到第三个控制点,因此通常从 -1 开始编号)。 到 Bezier 的转换如下:

Catmull-Rom 到 Bezier

[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]

Bezier 到 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 通常是主要表示形式。

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).

Bezier to Hermite

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

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.

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:

Catmull-Rom to Bezier

[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]

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]

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

泪冰清 2024-07-31 14:21:47

正如史蒂文提到的,您可以将三次埃尔米特曲线转换为三次贝塞尔曲线。 其实很简单。

典型的三次 Hermite 曲线由两个点和两个向量定义:

  • P0 -- 起点
  • V0 -- 在 P0 处的导数
  • P1 -- 终点
  • V1 -- P1 处的导数

转换为三次贝塞尔曲线很简单:

B0 = P0
B1 = P0 + V0/3
B2 = P1 - V1/3
B3 = P1

然后您可以使用求值器或任何其他工具绘制贝塞尔曲线你希望的方式。

As Steven mentioned, you can convert a cubic Hermite curve to a cubic Bezier curve. It's actually quite simple.

A typical cubic Hermite curve is defined with two points and two vectors:

  • P0 -- start point
  • V0 -- derivative at P0
  • P1 -- end point
  • V1 -- derivative at P1

The conversion to a cubic Bezier is simply:

B0 = P0
B1 = P0 + V0/3
B2 = P1 - V1/3
B3 = P1

You can then draw your Bezier curve using and evaluator or any other way you wish.

Hello爱情风 2024-07-31 14:21:47

您可以将任何 Hermite 曲线转换为 Bezier 曲线,然后进行绘制。 它们是使用 C3 中的两个不同基数简单定义的。 Google 并不是很有用,而且这似乎是一个常见问题,因此我们应该尝试使 StackOverflow 的答案变得明确,也许可以使用一些示例代码。 明天我会带着更多回来。

You can convert any Hermite curve into a Bezier curve and then draw that. They are simply defined using two different bases in C3. Google wasn't very useful, and it seems like this would be a common question, so we should try to make the StackOverflow answer definitive, maybe with some sample code. I'll come back tomorrow with more.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文