Solved

Area of a closed GraphicsPath

Posted on 2010-09-03
4
943 Views
Last Modified: 2012-05-10
I have a graphicspath shape in a picturebox, created from a set of lines and some beizer curves. does anyone know how to find the area of the shape. I know how find the points along any of the sides of the shape, and i know what the bounding rectangle is

thanks for any help

example image

 example image
0
Comment
Question by:SniperX1
4 Comments
 
LVL 21

Expert Comment

by:mastoo
ID: 33597196
Thinking back many many years, if you have equations for each segment you take the integral to get the area.  But it sounds like you have specific data points?  The simplest is to just loop through x = min to max in steps of deltax.  The area = sum of (y2 - y1) * deltax where y2 and y1 are the upper and lower curve coordinates.  There are more refined approximations, but that gets it done.  If you have an x with more than two y's (like in the middle of the graph) you need to calculate the upper and lower areas separately.  There are probably open source codes out there to do this, but you'd have to try your google skills with that.
0
 
LVL 4

Accepted Solution

by:
aaver earned 500 total points
ID: 33601127
What you need is a "relationship between a line integral around a simple closed curve C and a double integral over the plane region D bounded by C." (i.e. Green's theorem: http://en.wikipedia.org/wiki/Green%27s_theorem)

A special case of Green's theorem when the closed curve C is given by discrete coordinates is often called "Surveyor's Formula" (see under the paragraph "Area and centroid" here: http://en.wikipedia.org/wiki/Polygon)

If you have all vertices for the straight lines and enough points on the curved ones, the sum (area) should be easy to calculate.
0
 
LVL 18

Expert Comment

by:JoseParrot
ID: 33601496
By looking at the shape as an image, then what you have is a lot of pixels.
Assuming, for ease, that the image is a black and white with just 1 bit, then each pixel is 0 or 1. So, just count the number of pixels equal to 1 and you have the area.
As in CODE 1.
If the pixels are 8 bit deep, then CODE 2 applies.
The same approach is ok for color images.
The area is given in pixels. If you need the area in inches, for example, just calculate the area (as in CODE 1 or 2) and divide it by (N*N), being N the number of pixels by inch of your image.

// CODE 1 ---> image 1 bit deep

area = 0

for x=1 to width

   for y=1 to height

       if pixel(x,y) not zero then area = area + 1

   next y

next x

//---------------------------------

// CODE 2 ---> image 8 bit deep (256 levels)

area = 0

for x=1 to width

   for y=1 to height

       if pixel(x,y) not zero then area = area + pixel(x,y)

   next y

next x

area = area/256

      

Open in new window

0
 
LVL 1

Author Closing Comment

by:SniperX1
ID: 33602485
thanks for the help, it is very much appreciated.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SlingPlayer alternatives 1 35
SQL Login 17 40
Facial recognition to look through the whole database for a person 3 43
C# parent child form 5 19
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now