Calculate Bezier AABB

I would like to calculate the AABB (axis bounding rectangle) for a quadratic or bezel-less curve.

The only way I know how to do this is to evaluate a large number of points on the bezier curve, and then use these points to calculate AABB.

Is there a better way?

+4
source share
3 answers

An excellent resource on Bezier curves and a working AABB example http://pomax.imtqy.com/bezierinfo/#boundingbox For a quadratic curve, if you need it, also calculate this using derivatives.

Always avoid using iterative methods when a closed form is available.

+2
source

This should be possible by looking for the minimum and maximum due to the derivative of the curve in parametric form. take a look at this article: http://nishiohirokazu.blogspot.jp/2009/06/how-to-calculate-bezier-curves-bounding.html

+1
source

The quadratic Bezier curve consists of two coordinate functions - x (t) and y (t), where.

These functions can have a maximum or minimum (points where x '(t) = 0 and y' (t) = 0), and these points are the boundary points aabb.

So the algorithm:

  • Imagine that x0, y0, x1, y1, x2, y2 are known and calculate the values ​​t (x0, x1, x2) and t (y0, y1, y2) when x '(t) = 0 and y' t) = 0 respectively.
  • Calculate both values ​​and check if they are = = 0 and <= 1. If they evaluate quadratic bezier points.
  • Take the first and last points.
  • Now you have 4 points (or maybe less), use them to calculate AABB.

By the way:

t (x0, x1, x2) = (x0 - x1) / (x2 - 2 * x1 + x0)

t (y0, y1, y2) = (y0 - y1) / (y2 - 2 * y1 + y0)

Here you can find the full code: https://github.com/keyten/Graphics2D/blob/Delta/Core/Curve.Math.js#L295

0
source

Source: https://habr.com/ru/post/1345402/


All Articles