2

今日、私の脳は機能していません。ポイント(緯度、経度)がマップ上の長方形内にあるかどうかをテストする必要があります。長方形は、北、東、南、西の境界線によって定義されます。問題は、すべてのポイントまたは値がマップ座標系にあることです。日付行の折り返しに対処するために、左から右に移動する場合、経度は常に「間」であると想定します。

bool PointInRectangle(Point pt, double North, double East, double South, double West)
{
    // ????
}
4

1 に答える 1

3

東と北が正であると仮定すると:

bool PointInRectangle(Point pt, double North, double East, double South, double West)
{
    // you may want to check that the point is a valid coordinate
    if (West < East)
    {
        return pt.X < East && pt.X > West && pt.Y < North && pt.Y > South;
    }

    // it crosses the date line
    return (pt.X < East || pt.X > West) && pt.Y < North && pt.Y > South;        
}
于 2012-05-18T17:39:12.650 に答える