If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Welcome to Qt Centre.

Qt Centre is a community site devoted to programming in C++ using the Qt framework. Over 90 percent of questions asked here gets answered. If you are looking for information about Qt related issue — register and post your question.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Fill area of QPainterPath

Hello,

I'd like to ask if there's a way to calculate the area of a closed painter path. I'd like to calculate the common area of an ellipse and a polygon, and since QPainterPath supports intersecting paths, I thought I could solve the problem easily. I've searched for ellipse-polygon intersection on the net, but with no luck.
My idea is to paint the intersected path, and then count the pixels with the painter color. However this is very slow, and I'd like a fast(er) solution. Any help would be appreciated.

Re: Fill area of QPainterPath

I'm sorry to be confusing. By area I mean the mathematical area. Not in pixels, since that's only an approximation (or maybe that's good enough, since I don't see any other option). I'm talking about the geometrical area of the intersection of two geometrical objects. Is that clear now?

Re: Fill area of QPainterPath

Maybe for your purposes you can convert the QPainterPath to QPolygonF with toFillPolygon() method, and calculate area of polygon (which is just a set of points).
Now the question is - what precision do you need ? Conversion is always just an approximation. Next thing is precision when calculating the area. QPolygonF does not provide any methods for area calculation, so you'll need to implement one yourself.
If you want it to be very accurate and/or don't want to mess with the math yourself, maybe you can use some geometry library, like CGAL.
Simple "home-made" approximation could be to divide the boundingRect() of polygon to sub-rects, and for each of them check if polygon contains it's center. Then the "hit" ratio can be used to approximate area using total area of bounding rect. The more "sub-rects" you use, the more precision (and should be very simple to implement, since you have QPolygonF::containsPoint() method). Could be faster than drawing the painter path and counting the pixels too.