将二次贝塞尔曲线转换为三次贝塞尔曲线
将二次贝塞尔曲线(有 3 个点)转换为三次贝塞尔曲线(有 4 个点)的算法是什么?
What is the algorithm to convert a quadratic bezier (with 3 points) to a cubic one (with 4 points)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
来自 https://fontforge.org/docs/techref/bezier。 html#converting-truetype-to-postscript:
From https://fontforge.org/docs/techref/bezier.html#converting-truetype-to-postscript:
只是为已接受的答案提供证明。
二次贝塞尔曲线表示为:
三次方贝塞尔曲线表示为:
要使这两个多项式相等,它们的所有多项式系数必须相等。通过展开表达式(例如:(1-t)² = 1 - 2t + t²),然后对 1、t、t² 和 t³ 中的所有项进行因式分解来获得多项式系数:
因此,我们得到以下4个方程:
我们可以通过简单地将第二行中的 C0 替换为 Q0 来求解 C1 ,这给出:
那么,我们可以要么继续替代求解 C2,然后求解 C3,或者更优雅地注意到变量 t' = 1- 变化下原始方程的对称性t,并得出结论:
Just giving a proof for the accepted answer.
A quadratic Bezier is expressed as:
A cubic Bezier is expressed as:
For those two polynomials to be equals, all their polynomial coefficients must be equal. The polynomial coefficents are obtained by developing the expressions (example: (1-t)² = 1 - 2t + t²), then factorizing all terms in 1, t, t², and t³:
Therefore, we get the following 4 equations:
We can solve for C1 by simply substituting C0 by Q0 in the 2nd row, which gives:
Then, we can either continue to substitute to solve for C2 then C3, or more elegantly notice the symmetry in the original equations under the change of variable t' = 1-t, and conclude:
作为参考,我基于 上面 Owen 的回答为 NSBezierPath (macOS Swift 4) 实现了
addQuadCurve
。For reference, I implemented
addQuadCurve
for NSBezierPath (macOS Swift 4) based on Owen's answer above.