【发布时间】:2014-01-14 11:51:05
【问题描述】:
我在地图上绘制了一条路线(线)。对于这条路线,我有 2 个点,起点和终点分别是 (x1,y1) 和 (x2, y2)。
我需要找出线上的所有点。我为此使用中点公式。 以下是相同的代码。
private void GetAllPoints(GraphLocation start, GraphLocation end)
{
GraphLocation midPoint = GetMidPoint(start, end);
allPoints.Add(midPoint);
while (start.Latitude != midPoint.Latitude && start.Longitude != midPoint.Longitude)
{
GraphLocation point = GetMidPoint(start, midPoint);
midPoint = point;
allPoints.Add(point);
}
}
private GraphLocation GetMidPoint(GraphLocation start, GraphLocation end)
{
GraphLocation midPoint = new GraphLocation();
double dLon = DegreesToRadians(end.Longitude - start.Longitude);
double Bx = Math.Cos(DegreesToRadians(end.Latitude)) * Math.Cos(dLon);
double By = Math.Cos(DegreesToRadians(end.Latitude)) * Math.Sin(dLon);
midPoint.Latitude = RadiansToDegrees(Math.Atan2(
Math.Sin(DegreesToRadians(start.Latitude)) + Math.Sin(DegreesToRadians(end.Latitude)),
Math.Sqrt(
(Math.Cos(DegreesToRadians(start.Latitude)) + Bx) *
(Math.Cos(DegreesToRadians(start.Latitude)) + Bx) + By * By)));
midPoint.Longitude = start.Longitude + RadiansToDegrees(Math.Atan2(By, Math.Cos(DegreesToRadians(start.Latitude)) + Bx));
allPoints.Add(midPoint);
return midPoint;
}
此代码跳过了路线的某些部分。
请帮助我获得想要的结果。
【问题讨论】:
-
对找出一行上所有点的方程式或代码有问题吗?
-
一条线有无数个点...究竟是想要的结果是什么?
-
我尝试了一种方法,递归地使用中点公式断线,除非所有点都被覆盖。我无法弄清楚停止条件。
-
没有停止条件。一条线有无数个点。再说一次,你想做什么?为什么需要生成这些点?这是什么地图?这是什么路线?你的目标是什么?您如何确定您“缺少”积分,或者某些积分被“跳过”?
-
你是否试图沿着由这两个端点定义的线段生成一个均匀分布的点数组?
标签: c# algorithm latitude-longitude points