Question

From the docs:

QPainter offers two methods of painting QPolygons: drawPolygon and drawConvexPolygon.

Nowhere in the documentation is it made clear what the difference between them is. Additionally, the drawConvexPolygon docs state

If the supplied polygon is not convex, i.e. it contains at least one angle larger than 180 degrees, the results are undefined.

So... what is it for? I hoped the method would somehow find the convex hull of my polygon and paint that, however that doesn't seem to be the case.

Was it helpful?

Solution

The QPainter::drawConvexPolygon() documentation says:

On some platforms (e.g. X11), the drawConvexPolygon() function can be faster than the drawPolygon() function.

So,

  • drawPolygon() is more generic as it also allows to paint non-convex polygons (but drawing might be slower)
  • drawConvexPolygon() can only be used to draw convex polygons, but might be faster on specific platforms

For example, when doing 3D-rendering, you can use a Polygon Mesh which consists of convex polygons only to make rendering simpler, in which case the faster drawConvexPolygon() would be the better choice (since you need to paint a large number of convex polygons).

OTHER TIPS

Determining which part of the polygon is the outside and inside (for filling purposes) makes different choices depending on if the polygon contains a convex region. Think about how to determine the inside of a star shape vs. the inside of a rectangle.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top