0
$\begingroup$

I'm looking for algorithms or methods suitable for filling the area enclosed between complex curves - for example, the area within an outer ellipse but outside an inner ellipse, or the area bounded by two or more Bezier curves.

I'm familiar with the Flood Fill algorithm, which is quite universal, but it can also be inefficient and imprecise for complex shapes and large images.

I'm interested in alternatives, especially scanline-based methods. I understand that these work by intersecting the curves with horizontal or vertical lines and filling in the pixels between intersection points. However, the implementation details can get quite complex, especially for curves like ellipses or Bezier curves that require solving equations to find the intersection points.

Can anyone provide more detailed guidance or point me to resources about implementing these scanline fill methods for complex curves? Are there other, possibly more efficient or easier to implement, methods that I should consider?

Is analytical way to fast determine if point is inside such areas?

$\endgroup$

2 Answers 2

1
$\begingroup$

Define the curves to have a positive and negative side then determine which side of the curve the point in question lies on.

There are a few ways to do this, one method is to shoot a ray out, usually along one of the primary axis, such as the positive x axis and count how many times the ray crosses the curve. If the number is even it can be considered positive, if it is odd it can be considered negative.

Do this with every curve and keep a collision count. If the count is even it is inside, if it is odd it is outside depending on the direction the ray was cast.

This boils the problem down to colliding a ray with a Bezier curve for which there are many possible solutions.

It also depends on the winding direction of the curve which can be computed before hand.

$\endgroup$
0
$\begingroup$

Filling only requires pixel accuracy, so approximate solutions are quite acceptable. A simple but powerful method is to flatten the curves (i.e. turning them to polylines) and assemble the polylines to polygons.

Polygons can be filled by scanline processing.

Flattening can be done recursively as follows:

  • consider an arc of a parametric curve;
  • compute the point at the middle parameter value;
  • if the distance of that point to the chord exceeds a threshold, process both halves recursively;
  • otherwise, the curve is well approximated by the chord.

Technical note:

In some rare cases (around an inflexion point), the procedure can fail. A workaround is to subdivide one more time when the midpoint is found to be close. This is still not bulletproof, but the probability of failure is microscopic.


Also of interest:

https://stackoverflow.com/a/25992262/21508463

The method also applies to elliptic arcs, that fulfill a conic equation.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.