在OpenGL中绘制Hermite曲线
如何使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
令贝塞尔曲线的控制点向量为 [b0 b1 b2 b3],埃尔米特曲线的控制点向量为 [h0 h1 v0 v1](v0 和 v1 是点 h0 和 h1 处的导数/切线)。 然后我们可以使用矩阵形式来显示转换:
Hermite 到 Bezier
(这与上面 Naaff 的响应完全相同)。
Bezier 到 Hermite
因此,在矩阵形式中,这些可能比所需的稍微复杂一些(毕竟 Naaff 的代码简短而切题)。 它很有用,因为我们现在可以很容易地超越隐士。
特别是,我们可以引入另一个经典的基数三次参数曲线:Catmull-Rom 曲线。 它有控制点 [c_1 c0 c1 c2](与贝塞尔曲线不同,该曲线从第二个控制点延伸到第三个控制点,因此通常从 -1 开始编号)。 到 Bezier 的转换如下:
Catmull-Rom 到 Bezier
Bezier 到 Catmull-Rom
我也可以进行 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
(this is exactly as in Naaff's response, above).
Bezier to Hermite
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
Bezier to Catmull-Rom
I can do the Hermite to Catmull-Rom pair too, but they're rarely used, since Bezier is normally the primary representation.
正如史蒂文提到的,您可以将三次埃尔米特曲线转换为三次贝塞尔曲线。 其实很简单。
典型的三次 Hermite 曲线由两个点和两个向量定义:
P0
-- 起点V0
-- 在P0
处的导数P1
-- 终点V1
--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 pointV0
-- derivative atP0
P1
-- end pointV1
-- derivative atP1
The conversion to a cubic Bezier is simply:
You can then draw your Bezier curve using and evaluator or any other way you wish.
您可以将任何 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.