Can you use normal geometry for GPS locations to find whenever an point is inside an rectangle

Viewed 54

I'm trying to check whether a point is inside a rectangle area of a map that uses GPS.

Input data:

  • coordinates (x1,y1) of the left top point of a map area (NW)
  • coordinates (x2,y2) of the right bottom point of a map area (SE)
  • coordinates (x3,y3) of the point on a map

Output data:

  • True - if the point is on a map area
  • False - if it isn't there

The point is inside the map viewport on the screenshot: screenshot

Currently, I'm using the basic math geometry method to check whether a point is inside a rectangle area: if x1 < x3 < x2 and y2 < y3 < y1 then the point is inside a map, so it's True.

But is it a true way to solve this issue?

A little code example on Python just to show an idea:

def point_in_map(nw_coordinates, se_coordinates, point_coordinates):
    return nw_coordinates[0] < point_coordinates[0] < se_coordinates[0] and \
           se_coordinates[1] < point_coordinates[1] < nw_coordinates[1]


is_point_in_map = point_in_map(
    (20.1913350, -0.1483518),
    (40.1913350, -0.7883518),
    (30.367, -0.4483518)
)

print(is_point_in_map)

So the printed result is True: code result

I'll be grateful for your help here!

0 Answers
Related