1

I want to calculate the area inside an object which is any closed object like rectangle ,square ,polygon etc.

enter image description here

I can not get exact solution to do this.Please help to find it.

Thanks.

Nirav D
  • 71,513
  • 12
  • 161
  • 183
Dhaval Umraliya
  • 410
  • 1
  • 4
  • 22

2 Answers2

2

For arbitrary polygons with known vertice coordinates you can use Shoelace formula

A = 1/2 * Abs(Sum{i=0..n-1} (X[i] * Y[i+1] - X[i+1] * Y[i]) )

where for i=n-1 take i+1=0

MBo
  • 77,366
  • 5
  • 53
  • 86
0

I am using this method which will give me closed object's area.It may be helpful for you.

-(double)areaWithXpts :(NSArray *)xpts withYpts :(NSArray *)ypts totalPoints :(int)numPoints
{
  double area=0;
  int j=numPoints-1;
   for(int i=0 ; i < numPoints;i++)
   {
       area=area+([[xpts objectAtIndex:j] floatValue]+[[xpts objectAtIndex:i] floatValue])*([[ypts objectAtIndex:j] floatValue]-[[ypts objectAtIndex:i] floatValue]);
       j=i;
   }
  double areaVal=area/2;
  NSLog(@"Area is :%f",areaVal);

  return areaVal;
}

Usage :

Array of X points

NSArray *xArray =[NSArray arrayWithObjects:@"0", @"10", @"10",  @"29",nil];

Array of Y points

NSArray *yArray =[NSArray arrayWithObjects:@"4", @"26", @"26", @"4",nil];

Total points = Array count.

Note: x array and y array both have same count.

double objectArea = [self areaWithXpts:xArray withYpts:yArray totalPoints:4];

Or you can check this answer also - Area calculation in objective c

And about area with curve shape object : you can find reference from this link - Curve shape object area reference

Community
  • 1
  • 1
iDeveloper
  • 607
  • 5
  • 25