Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/105.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在ios中查找封闭对象内的区域_Ios_Geometry_Area - Fatal编程技术网

在ios中查找封闭对象内的区域

在ios中查找封闭对象内的区域,ios,geometry,area,Ios,Geometry,Area,我想计算对象内部的面积,该对象是任何闭合对象,如矩形,正方形,多边形等 我无法得到精确的解决方案。请帮助找到它 谢谢。对于具有已知垂直坐标的任意多边形,您可以使用 其中对于i=n-1takei+1=0我正在使用此方法,它将给出闭合对象的面积。它可能对您有所帮助 -(double)areaWithXpts :(NSArray *)xpts withYpts :(NSArray *)ypts totalPoints :(int)numPoints { double area=0; int

我想计算对象内部的
面积
,该对象是任何闭合对象,如
矩形
正方形
多边形

我无法得到精确的解决方案。请帮助找到它


谢谢。

对于具有已知垂直坐标的任意多边形,您可以使用


其中对于
i=n-1
take
i+1=0

我正在使用此方法,它将给出闭合对象的面积。它可能对您有所帮助

-(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;
}
Y点阵列

NSArray *yArray =[NSArray arrayWithObjects:@"4", @"26", @"26", @"4",nil];
总分=阵列计数

注意:x数组和y数组的计数相同

double objectArea = [self areaWithXpts:xArray withYpts:yArray totalPoints:4];
或者你也可以检查这个答案-

关于曲线形状对象的面积:您可以从以下链接找到参考-

NSArray *yArray =[NSArray arrayWithObjects:@"4", @"26", @"26", @"4",nil];
double objectArea = [self areaWithXpts:xArray withYpts:yArray totalPoints:4];