0

I have a polygon that contains latitude and longitude as:

polygon= [[latitude1, longitude1], [[latitude2, longitude2]]....[latitudeN, longitudeN]]

The result of the shape is a circle, I want to calculate the distance from a point to the polygon. I know how to find the distance from one point to another, so I can iterate over all points in the polygon and find distance against my point to find minimum distance but is there another way?

Edit-1: I have some satellites footprints over a map, those footprints are presented as a polygons. I have some other points (locations) and I want to see which satellite is closer to each point and calculate the distance to that satellite

Sun Soul
  • 33
  • 7
  • Does this answer your question? [Distance from a point to a polygon](https://stackoverflow.com/questions/10983872/distance-from-a-point-to-a-polygon) – Gassa Apr 04 '22 at 09:34
  • There is a Matlab code in there, I will check it thank you – Sun Soul Apr 04 '22 at 09:47
  • @Gassa: beware that the polygon is on a sphere. That makes a difference. –  Apr 04 '22 at 12:15
  • 1
    The distance to a polygon is not the shortest distance to the vertices but the shortest to the edges or vertices. If preprocessing is not allowed, exhaustive comparison cannot be avoided. –  Apr 04 '22 at 12:16
  • Why do you want this distance, I suspect an XY problem ?.. –  Apr 04 '22 at 12:17

1 Answers1

2

In the case that the polygon indeed describes a circle, you could save the polygon as a center location (x,y) coordinate and the radius of the circle. The distane of a point to the polygon can be computed as the distance from the center of the circle to the wanted point, and then reduce the raidus size. As a bonus, if the resulted distance is negative, your point is inside the circle.

Tomer Geva
  • 1,764
  • 4
  • 16
  • Thank you sir, that's right but what if the polygon is not a circle – Sun Soul Apr 04 '22 at 09:31
  • 2
    The way you described the question suggested that the shape is a circle, For a non symetric shape it will be more complicated – Tomer Geva Apr 04 '22 at 09:34
  • Yes , I tried to use cross-track distance, I know how to find bearing and angular distance from point to another as described here http://www.movable-type.co.uk/scripts/latlong.html but that did not work – Sun Soul Apr 04 '22 at 09:37
  • @SunSoul This answer perfectly answers the question and you should accept it. You just can't change the rules of the game during the match simply by saying *What if the polygon is not circle?*. That would be another question, another game. Having said that in that particular case you should, vertex by vertex check the distances to your point and whichever neighboring vertices yield the closest average distance take the edge defined by those vertices as a line and [find a perpendicular line from your point to that edge](https://rb.gy/21cmmc). If not intersecting then return the closest vertex – Redu Apr 04 '22 at 17:51
  • 1
    Thank you @redu this was helpful also. The answer accepted – Sun Soul Apr 05 '22 at 18:30