2013-08-19 64 views
1

我是iOS新手,目前我正在计算mapview中多边形的面积。 我只有一个不规则多边形的边的长度,任何人都可以告诉我如何可以测量多边形的面积?只记住所有边的长度,没有角度或坐标。ios中使用边长的不规则多边形的区域

很少有论坛提到有关多边形等行为的问题但我只有边长。

有没有人有任何反馈?

谢谢。

+0

你可以这个链接,它可能会帮你一下http://www.wikihow.com/Sample/Area-of-an-Irregular-Polygon。但是你必须找到一个逻辑来获得坐标。 – Exploring

+0

这是一个数学问题,而不是编程问题。考虑在http://math.stackexchange.com/上提问。 –

+4

这个问题似乎是题外话,因为它是关于数学,而不是编程。 –

回答

3

我认为你不能做到这一点从这些信息,因为它可能是凸或凹还有: enter image description here

您需要更多的信息来做到这一点。

+1

即使对于凸形,您也无法从边长确定区域(想象一下矩形与具有相同边长的平行四边形)。 –

+1

实际上,我无法将经纬度转换为笛卡儿坐标(x,y),这就是我找到两个坐标(纬度,经度)之间距离的原因。我已经通过下面的链接,但我没有得到确切的价值http://stackoverflow.com/questions/1185408/converting-from-longitude-latitude-to-cartesian-coordinates你能帮我吗有没有其他的方式计算在mapview中写入的不规则多边形的面积。谢谢!! – user1482232

+0

我面对同样的问题请在这里回答http://stackoverflow.com/questions/18311091/how-to-calculate-irregular-shape-polygon-area-draw-on-map-in-ios 如果有人知道 – python

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; 
} 
+0

好吧,OP明确表示“没有角度或坐标”。 - 无论如何,在[[a + 1%N]]中都缺少括号...... –

+0

感谢您的及时回应,但我无法从经纬度获得确切的笛卡尔值,所以这就是我拥有的原因选择了这个选项。有没有其他方法来计算不规则多边形的面积(地图)。再一次感谢你。 – user1482232

0

希望您可以通过以下方式转变CLLocationCoordinate2DCGPoint,那么你就可以拥有所有点的坐标。

//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]];   
} 

希望这个代码片段可以帮助你。

+0

我正在使用下面的方法将坐标转换为CGPoint,但我无法得到确切的笛卡尔点。 CGPoint Point = [self.mapView convertCoordinate:self.mapCoordinate toPointToView:self.mapView];谢谢!! – user1482232

+0

@ user1482232谢谢你让我知道我的错误。 – Exploring

+0

我用CGPoint myPoint = CGPointMake(coordinate.longitude,coordinate.latitude);这种方法,但我没有得到确切的价值。请协助我,是否有其他方式将坐标转换成cgpoints。谢谢!1 – user1482232