Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Algorithm to Fill In a Closed 2D Curve [closed]

I need to find a way of drawing the inside of a closed 2D curve. This curve is actually created using a bicubic Bezier curve, but that's not important I believe.

At the moment there should be no "holes" within the drawn shape. So it will just be totally filled in. It seems like constrained Delaunay triangulation would be the way to go? But there seems to be different ways of doing this. I am looking for a quick and simple solution (but will implement what's needed to make it working).

Programs such as Illustrator have that sort of feature (or SVG -- with the option fill).

I am looking for:

  • techniques to do that
  • point me to a paper/document where the algorithm is explained
  • is the source code of a SVG renderer available somewhere?

EDIT:

  • The application uses OpenGL. I draw the curves myself. Just need to find a way of filling them in.
  • the shape can either be concave or convex
like image 907
user18490 Avatar asked Sep 21 '14 21:09

user18490


1 Answers

If you must use polygon filling, there is no other option than flattening the curve to get straight sides.

Then use a polygon filling primitive.

If all you have is a triangle filling primitive, you can

  • triangulate the polygon by ear clipping, or decomposition in monotone polygons, or

  • use a simple sweepline method: if you draw an horizontal through every vertex, you will slice the polygon in triangles and trapezoids. A trapezoid can be cut in two triangles. For efficiency, use the active list method.

like image 125
Yves Daoust Avatar answered Nov 08 '22 10:11

Yves Daoust