0

緯度と経度の座標を持つポイントのリストがあり、そこからXなどのポイントを入力します。そのポイントxに最も近い3つのリストメンバーを決定するためのアルゴリズムを考え出すのに助けが必要です。

4

1 に答える 1

1

基本的には、これを3D最近傍点問題としてアプローチできます。(現在、Lat / Lon to Cartesian(x、y、z)calcは手元にありませんが、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;
}
于 2012-07-06T07:31:10.310 に答える