如何偏移三次贝塞尔曲线?

发布于 2024-10-01 14:50:33 字数 493 浏览 9 评论 0 原文

我正在尝试创建一条“平行”贝塞尔曲线。在我的尝试中,我已经接近了,但没有雪茄。我试图在两条曲线(红色,蓝色)之间保持固定的 1px 偏移。

当前尝试

我的主要目标是使用边缘偏移算法来扩展/缩小 svg 路径。


解决方案

对于正在寻找解决方案的其他人,我创建了一个 AS3 版本。

http://seant23.wordpress.com/2010/11/12/偏移贝塞尔曲线/

I'm trying to create a "parrallel" bezier curve. In my attempts I've gotten close but no cigar. I'm trying to keep a solid 1px offset between the 2 curves (red,blue).

current attempt

My main goal is use a edge offseting algorythm to expand/shrink a svg path.


Solution

For anyone else who is looking for a solution, I've create a AS3 version.

http://seant23.wordpress.com/2010/11/12/offset-bezier-curves/

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

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

发布评论

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

评论(4

爱本泡沫多脆弱 2024-10-08 14:50:34

您所要求的在数学中称为平行或偏移曲线。关于贝塞尔曲线的维基百科文章(上面被其他人引用)未能链接到“偏移曲线”的正确文章,但我几秒钟前已经修复了这个问题。在矢量图形的世界中,同样的概念被称为抚摸路径。

一般来说,对于三次/贝塞尔曲线,偏移曲线是 10 阶多项式!资料来源:Kilgard,第 14 页28

如果您只想光栅化此类偏移曲线,而不是计算它们的解析形式,那么您可以查看 Ghostscript 的来源。您还可以查看此专利申请,了解 NV_path_rendering 是如何实现的。

如果你想隐藏/近似偏移曲线,那么MetaFog 上的 TUG 论文 涵盖 METAFONT 到 PostScript 字体是一本很好的读物。 METAFONT 系统早于 PostScript,允许通过(数学上更复杂的)描边操作来描述字体,但出于速度原因,PostScript Type 1 字体仅允许使用填充(与一般的 PostScript 绘图不同)。

Gernot Hoffmann 的这篇论文。 (向 OpenGL 论坛上找到它的人致敬。)

事实上有很多这样的算法。我发现了1997年调查各种近似偏移量的算法曲线。他们假设祖曲线是贝塞尔曲线或 NURBS 曲线。

What you ask for is called a parallel or offset curve in mathematics. The Wikipedia article (quoted above by others) on Bezier curves failed to link to the right article for "offset curve", but I've fixed that a few seconds ago. In the world of vector graphics, that same notion is called stroking the path.

In general, for cubic/Bezier curve the offset curve is a 10th order polynomial! Source: Kilgard, p. 28

If all you want to do is rasterize such offset curves, rather than compute their analytic form, you can for example look at the sources of ghostscript. You could also look at this patent application to see how NV_path_rendering does it.

If you want to covert/approximate the offset curves, then the TUG paper on MetaFog for covering METAFONT to PostScript fonts is a good reading. The METAFONT system, which predated PostScript allowed fonts to be described by the (more mathematically complex) operation of stroking, but PostScript Type 1 fonts only allow filling to be used (unlike PostScript drawings in general) for reasons of speed.

Another algorithm for approximating the offsets as (just two) Beziers (one on each side), with code in PostScript, is given in section 7 of this paper by Gernot Hoffmann. (Hat tip to someone on the OpenGL forum for finding it.)

There are in fact a lot of such algorithms. I found a 1997 survey of various algorithms for approximating offset curves. They assume the progenitor curves are Beziers or NURBS.

oО清风挽发oО 2024-10-08 14:50:34

一般来说,不可能将三次贝塞尔曲线的偏移表示为三次贝塞尔曲线(具体来说,当尖点或曲率半径接近偏移距离时,这是有问题的)。但是,您可以将偏移近似到任何精度级别。

试试这个:

  • 偏移有问题的贝塞尔曲线(你已经看起来相当不错)
  • 测量每条原始曲线和相应偏移曲线之间的差异。我会尝试 10 个样本,看看效果是否良好。
  • 对于超出公差的任何偏移,请细分(使用贝塞尔曲线的 deCastlejau 算法)并迭代。

我还没有实现偏移(因为我使用的内核已经有一个),但这似乎是值得尝试的事情。

It's not possible in general to represent the offset of a cubic Bezier curve as a cubic Bezier curve (specifically, this is problematic when you have cusps or radius of curvature close to the offset distance). However, you can approximate the offset to any level of accuracy.

Try this:

  • Offset the Beziers in question (what you have already seems pretty decent)
  • Measure the difference between each original curve and corresponding offset curves. I'd try something like 10 samples and see if it works well.
  • For any offset that's outside of tolerance, subdivide (using the deCastlejau algorithm for Beziers) and iterate.

I haven't implemented an offset (because the kernels I use already have one), but this seems like something to try.

仅一夜美梦 2024-10-08 14:50:33

我希望您发现我的数学论文有用在此处输入图像描述

选择性细分的二次贝塞尔曲线偏移
https://microbians.com/mathcode

I hope you found my math paper usefulenter image description here

Quadratic bezier offsetting with selective subdivision
https://microbians.com/mathcode

你怎么敢 2024-10-08 14:50:33

来自维基百科:( http://en.wikipedia.org/wiki/B%C3% A9zier_curve )

与给定贝塞尔曲线有固定偏移的曲线,通常称为偏移曲线(与原始曲线“平行”,就像铁轨中钢轨之间的偏移),不能精确地由贝塞尔曲线(除了一些微不足道的情况)。然而,有一些启发式方法通常可以为实际目的提供足够的近似值。

您可能还会看到此处指出的论文:
三次贝塞尔曲线描边轮廓

From wikipedia: ( http://en.wikipedia.org/wiki/B%C3%A9zier_curve )

The curve at a fixed offset from a given Bézier curve, often called an offset curve (lying "parallel" to the original curve, like the offset between rails in a railroad track), cannot be exactly formed by a Bézier curve (except in some trivial cases). However, there are heuristic methods that usually give an adequate approximation for practical purposes.

You might also see the paper indicated here:
Outline of cubic bezier curve stroke

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