计算贝塞尔曲线AABB
我想计算二次曲线或贝塞尔曲线的 AABB(轴对齐边界框)。
我知道如何做到这一点的唯一方法是评估贝塞尔曲线上的大量点,然后使用这些点来计算 AABB。
有更好的办法吗?
I'd like to calculate the AABB (axis aligned bounding box) for a quadratic or bezier curve.
The only way I know how to do this is evaluating a high number of points on the bezier curve, and then use those points to calculate the AABB.
Is there a better way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
关于贝塞尔曲线的丰富资源,以及 AABB 的工作示例 http://pomax.github.io/bezierinfo/#边界框
对于二次曲线,如果需要的话,也可以使用导数来计算。
当封闭形式可用时,始终避免迭代方法。
Great resource on Bezier curves, and working example of AABB http://pomax.github.io/bezierinfo/#boundingbox
For quadratic curve if you need it, also calculate this using derivatives.
Always avoid iterative methods when closed form is available.
由于参数形式的曲线导数,应该可以通过寻找最小值和最大值来实现。看看这篇文章: http:// nishiohirokazu.blogspot.jp/2009/06/how-to-calculate-bezier-curves-bounding.html
It should be possible by looking for minimum and maximum thanks to the derivative of the curve in parametric form. have a look at this article: http://nishiohirokazu.blogspot.jp/2009/06/how-to-calculate-bezier-curves-bounding.html
二次贝塞尔曲线由 2 个坐标函数组成 — x(t) 和 y(t),其中。
这些函数可能具有最大值或最小值(x'(t) = 0 和 y'(t) = 0 的点),这些点是 aabb 的边界点。
所以算法是:
顺便说一下:
t(x0, x1, x2) = (x0 - x1) / (x2 - 2 * x1 + x0)
t(y0, y1, y2) = (y0 - y1) / (y2 - 2 * y1 + y0)
您可以在此处找到完整代码: https: //github.com/keyten/Graphics2D/blob/Delta/Core/Curve.Math.js#L295
The quadratic bezier curve consists of 2 coordinate functions — x(t) and y(t) where.
These functions may have maximum or minimum (the points where x'(t) = 0 and y'(t) = 0) and these points are the boundary points of the aabb.
So the algorithm is:
By the way:
t(x0, x1, x2) = (x0 - x1) / (x2 - 2 * x1 + x0)
t(y0, y1, y2) = (y0 - y1) / (y2 - 2 * y1 + y0)
You can find the full code here: https://github.com/keyten/Graphics2D/blob/Delta/Core/Curve.Math.js#L295