0

Given a coordinate, construct a bounding box that is +/- N degrees from that coordinate. The bounding box will be determined by lat_min, lat_max, lng_min and lng_max.I have the following code in Java (Assume all input are in degrees):

static class BoundingBox
{
    private final double lat_min;
    private final double lng_min;
    private final double lat_max;
    private final double lng_max;

    public BoundingBox(double lat, double lng, double N)
    {
        this.lat_min = lat - N;
        this.lat_max = lat + N;
        this.lng_min = lng - N;
        this.lng_max = lng + N;
    }

    public boolean contains(double lat, double lng)
    {
        if (lat_max < lat)
            return false;

        if (lat_min > lat)
            return false;

        if (lng_max < lng)
            return false;

        if (lng_min > lng)
            return false;

        return true;
    }
}

Is this right?

Prasanna
  • 3,703
  • 9
  • 46
  • 74
  • Have you tried it? If I were your teacher, I'd test your code near the international date line, and near the poles. – Beta Jun 09 '12 at 12:54

1 Answers1

0

A bounding box is is a rectangular prism that contains a given object. The minimum bounding box is the one with the least volume or surface area.

tskuzzy
  • 35,812
  • 14
  • 73
  • 140