0

What are the approaches to color-filling a curved concave shape in libgdx?

Let us assume that:

1) The shape-to-be-rendered is built from an array of vertices that are close to each other.

2) Edges between the vertices are known.

3) The vertices' positions might dynamically change over time. We are guaranteed that no self-intersections will occur (and that the shape will not be hollow).

enter image description here

The right-most picture is what I'm trying to render in libgdx (with-or-without the outline).

From what I've read, triangulation is a popular approach to non-curved shapes, but in order for it look any good for shapes with curvature, I imagine we would need a huge number of vertices (so that the many lines "zoomed out" resemble a smooth curve).

P. Lance
  • 169
  • 1
  • 11

1 Answers1

1

Triangulatin is not the only one way to go with this. I am not familiar with your gfx lib but I would do this in low level:

  1. Subdivide your polyline to set of convex ones

    you need to know which segment is line and which is curve and for the curve you also need to know the control points from neighboring patch so the connection is smooth. The concave boundary can be detected by the fact that angle change swaps sign so if you got consequent points p(0)...p(n) with consistent widing rule then

    d(i  ) = p(i+1)-p(i  )
    d(i-1) = p(i  )-p(i-1)
    n(i) = cross( d(i) , d(i-1) )
    n(i).z * n(i-1).z < 0.0
    

    so the cross product will give you normal and if the direction of the normal swaps it mean the winding is changed... The equatio assumes points are in xy plane or parallel to it. If not the case the last line should be

    dot( n(i) , n(i-1) ) < 0.0
    

    if true p(i) is your concave boundary and you should split your shape by it

  2. fill the polylines

    you can use the same approach as for triangles or convex polygons see:

  3. render polyline outline

Of coarse if you do not have fast pixel access or horizontal line rendering available is this not a good way to go. There is one simple but not as fast option:

  1. render outline

  2. flood fill inside

    this step is slow which might cause problems for bigger resolutions.

Spektre
  • 45,598
  • 10
  • 100
  • 347