我有纬度和经度坐标的点列表,我想从中输入一个说X的点。我需要帮助提出一个算法,以确定最接近该点的3个列表成员x。
答案 0 :(得分:1)
您基本上可以将此视为3D最近点问题。 (我现在没有Lat / Lon到Cartesian(x,y,z)的计算方法,但你可以很容易地找到使用google)。
public class LatLonPoint
{
public double Latitude { get; set; }
public double Longitude { get; set; }
public double X
{
get
{
.......
}
}
public double Y ....
public double Z .....
public double DistanceTo(LatLonPoint point)
{
double dX = point.X - X;
double dY = point.Y - Y;
double dZ = point.Z - Z;
return Math.Sqrt(dX * dX + dY * dY + dZ * dZ);
}
}
您的班级代码:
// Your list of points
private List<LatLonPoint> _points = new List<LatLonPoint>();
public LatLonPoint FindClosestPoint(LatLonPoint x)
{
var closestPoint = null;
double closestDistance = double.MaxValue;
foreach (var point in latLonList)
{
double distanceToPoint = point.DistanceTo(x);
if (distanceToPoint < closestDistance)
{
closestPoint = point;
closestDistance = distanceToPoint;
}
}
return closestPoint;
}