skyline中多边形面积计算

skyline中多边形面积计算

慕运维8079593
浏览 416回答 1
1回答

绝地无双

/// <summary> &nbsp; &nbsp; &nbsp; &nbsp;/// 多边形面积计算(不论凸凹) &nbsp; &nbsp; &nbsp; &nbsp;/// </summary> &nbsp; &nbsp; &nbsp; &nbsp;/// <param name="N">坐标点数即多边形的边数</param> &nbsp; &nbsp; &nbsp; &nbsp;/// <param name="X">坐标的横坐标集合</param> &nbsp; &nbsp; &nbsp; &nbsp;/// <param name="Y">坐标的纵坐标集合</param> &nbsp; &nbsp; &nbsp; &nbsp;/// <returns>多边形的面积</returns> &nbsp; &nbsp; &nbsp; &nbsp;public static double Area(int N, double[] X, double[] Y) &nbsp; &nbsp; &nbsp; &nbsp;{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;double area; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (N < 3) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return 0; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;area = Y[0] * (X[N - 1] - X[1]); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for (int i = 1; i < N; i++) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;area += Y * (X[(i - 1)] - X[(i + 1) % N]); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return area / 2; &nbsp; &nbsp; &nbsp; &nbsp;}&nbsp;可将经纬度转换成二维坐标后使用上面的方法计算
打开App,查看更多内容
随时随地看视频慕课网APP