我是iOS新手,目前我正在研究mapview中多边形的面积。 我只有不规则多边形的边长,谁能告诉我如何测量多边形的面积?只记住所有边的长度,没有角度或坐标。
很少有论坛提到多边形等的遗骸,但我只有边长。
有人有任何反馈吗?
感谢。
答案 0 :(得分:3)
我认为你不能从那些信息中做到这一点,因为它可能是凸的或凹的:
您需要更多信息才能做到这一点。
答案 1 :(得分:1)
如果你可以得到多边形中每个角的点,你可以使用它:
float area = 0;
int N = pointArray.count;
for (int a = 0; a < N-1; a++) {
float term = ([pointArray[a] CGPointValue].x * [pointArray[a+1 % N] CGPointValue].y -
[pointArray[a+1 % N] CGPointValue].x * [pointArray[a] CGPointValue].y)/2.0;
area += term;
}
答案 2 :(得分:0)
希望您可以通过以下方式将CLLocationCoordinate2D
转换为CGPoint
,然后您可以拥有所有点的坐标。
//CGPoint myPoint = CGPointMake(coordinate.longitude, coordinate.latitude);
CGPoint Point = [self.mapView convertCoordinate:self.mapCoordinate toPointToView:self.mapView];
然后你可以尝试按照链接
的方式http://www.wikihow.com/Sample/Area-of-an-Irregular-Polygon
CLLocationCoordinate2D overflowLotCoords[15]={
CLLocationCoordinate2DMake(39.04864351611461,-76.8513227245313),
CLLocationCoordinate2DMake(39.04851710015167,-76.8517540587399),
CLLocationCoordinate2DMake(39.04868674731313,-76.85192728689483),
CLLocationCoordinate2DMake(39.04850095882104,-76.85230365946416),
CLLocationCoordinate2DMake(39.04819087100218,-76.85265260435219),
CLLocationCoordinate2DMake(39.0477370134458,-76.85286078490296),
CLLocationCoordinate2DMake(39.04692851484644,-76.85283202926037),
CLLocationCoordinate2DMake(39.04695987529381,-76.85235192135768),
CLLocationCoordinate2DMake(39.04734847050665,-76.85236298239703),
CLLocationCoordinate2DMake(39.04779491740192,-76.85232236959109),
CLLocationCoordinate2DMake(39.04814366462639,-76.85208905182692),
CLLocationCoordinate2DMake(39.04838024069194,-76.85164072166863),
CLLocationCoordinate2DMake(39.04843331131504,-76.85085998781742),
CLLocationCoordinate2DMake(39.04857547181026,-76.8507923535788),
CLLocationCoordinate2DMake(39.04864351611461,-76.8513227245313)
};
NSMutableArray *marrPointsList = [NSMutableArray array];
for (int i = 0; i < 15; i++)
{
CLLocationCoordinate2D coordinate = overflowLotCoords[i];
CGPoint point = [self.myMapView convertCoordinate:overflowLotCoords[i] toPointToView:self.myMapView];
NSLog(@"convert %@", NSStringFromCGPoint(point));
[marrPointsList addObject:[NSValue valueWithCGPoint:point]];
}
希望此代码段可以为您提供帮助。