- 以真北为0度起点,由东向南向西顺时针旋转360度,主要是用于控制象限。
根据2点经纬度,计算方位角[csharp] /// <summary> /// 给定2点,获得经纬度 /// </summary> /// <param name="startPoint">起点经纬度,都是以度为单位</param> /// <param name="endPoint">终点经纬度,都是以度为单位</param> /// <returns></returns> private double GetLineAngle(Point2D startPoint, Point2D endPoint) { double mathPI = 3.1415926535897931; double tmpValue = 0; double latStart = startPoint.Y * mathPI / 180; double lngStart = startPoint.X * mathPI / 180; double latEnd = endPoint.Y * mathPI / 180; double lngEnd = endPoint.X * mathPI / 180; if (startPoint.X == endPoint.X || startPoint.Y == endPoint.Y) { if (startPoint.X == endPoint.X) { /// 经度相同 if (endPoint.Y >= startPoint.Y) { return 0; } else { return 180; } } else { /// 纬度相同 if (endPoint.X >= startPoint.X) { return 90; } else { return 270; } } } tmpValue = Math.Sin(latStart) * Math.Sin(latEnd) + Math.Cos(latStart) * Math.Cos(latEnd) * Math.Cos(lngEnd - lngStart); tmpValue = Math.Sqrt(1 - tmpValue * tmpValue); tmpValue = Math.Cos(latEnd) * Math.Sin(lngEnd - lngStart) / tmpValue; double resultAngle = Math.Abs(Math.Asin(tmpValue) * 180 / mathPI); if (endPoint.X > startPoint.X) { if (endPoint.Y >= startPoint.Y) { /// 第一象限 return resultAngle; } else { /// 第二象限 return 180 - resultAngle; } } else { /// 第四象限 if (endPoint.Y >= startPoint.Y) { return 360 - resultAngle; } else { /// 第三象限 return 180 + resultAngle; } } } [/csharp]
计算线的夹角:[csharp] double lastAngle = GetLineAngle(tempvPoints[k-1], tempvPoints[k]); double thisAngle = GetLineAngle(tempvPoints[k], tempvPoints[k + 1]); double angle = Math.Abs(thisAngle - lastAngle); if (angle > 180) { angle = 360 - angle; } angle = 180 - angle; [/csharp]
参考文档:http://linfengsheng.iteye.com/blog/1473037
http://blog.sina.com.cn/s/blog_658a93570101hynw.html