将由轮廓样条线构建的形状转换为简单的多边形

发布于 2024-08-31 09:13:01 字数 359 浏览 9 评论 0原文

我已经从 truetype 文件中转储了字形,以便我可以使用它们。它们的形状轮廓由二次贝塞尔曲线和直线组成。我想输出此类形状的三角形,以便我可以为用户可视化它们。

传统上我可能会使用 libfreetype 或 scan-rasterise 这种轮廓。但我想从字体中生成挤压 3D 网格,并用它们进行其他扭曲。

那么,如何对由二次贝塞尔曲线和直线组成的形状进行多边形化呢?有许多轮廓一起形成形状。一些轮廓是加法的,而另一些是减法的。轮廓永远不会开放。它们形成一个循环。

(实际上,我只从 ttf 字形中获得轮廓顶点,这些顶点定义它们是否是曲线的一部分。尽管很容易将它们分解为贝塞尔曲线和直线,但知道数据以这种方式表示可能会有所帮助将轮廓多边形化为三角形)

I've dumped glyphs from truetype file so I can play with them. They have shape contours that consist from quadratic bezier curves and lines. I want to output triangles for such shapes so I can visualize them for the user.

Traditionally I might use libfreetype or scan-rasterise this kind of contours. But I want to produce extruded 3D meshes from the fonts and make other distortions with them.

So, how to polygonise shapes consisting from quadratic bezier curves and lines? There's many contours that form the shape together. Some contours are additive and others are subtractive. The contours are never open. They form a loop.

(Actually, I get only contour vertices from ttf glyphs, those vertices define whether they are part of the curve or not. Even though it is easy to decompose these into bezier curves and lines, knowing the data is represented this way may be helpful for polygonizing the contours to triangles)

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

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

发布评论

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

评论(1

滿滿的愛 2024-09-07 09:13:01

这很简单。您需要对曲线实施布尔运算,然后继续连接成对的曲线,直到只剩下一条曲线。

首先,您需要评估曲线并将其转换为折线。

然后,您需要确保两个轮廓相交的每个地方都有一个顶点(由于数字错误,这部分实际上可以尝试;您可以使用 Bentley-Ottmann 算法)。

最后,您需要做的就是遍历曲线并以正确的顺序连接它们以执行布尔运算,生成 弱简单多边形

可以使用例如耳朵裁剪算法对此类多边形进行三角测量(该算法很慢,但很简单)实施)。

希望这有帮助...

This is simple. You need to implement boolean operations on your curves, then proceed by joining pairs of curves untily you are left with a single curve.

First, you need to evaluate the curves and convert them to polylines.

Then you need to make sure that there is a vertex at every place where two contours intersect (this part can actually be trying, due to the numeric errors; you can use the Bentley-Ottmann algorithm).

Finally, all you need to do is to traverse the curves and connect them in the correct order to perform the boolean operation, producing weakly simple polygons.

Such polygons can be triangulated using e.g. ear clipping algorithm (which is slow, but rather simple to implement).

Hope this helps ...

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