Link to home
Start Free TrialLog in
Avatar of SniperX1
SniperX1Flag for United Kingdom of Great Britain and Northern Ireland

asked on

Area of a closed GraphicsPath

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

 User generated image
Avatar of mastoo
mastoo
Flag of United States of America image

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.
ASKER CERTIFIED SOLUTION
Avatar of aaver
aaver
Flag of Afghanistan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Jose Parrot
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

Avatar of SniperX1

ASKER

thanks for the help, it is very much appreciated.