Search code examples
qtqpainterconvex-hull

What's the point in QPainter::drawConvexPolgon


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.


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).