0

I want to calculate all geo coordinates between two geo points(lat/long) on earth. I would like to have a python solution for this problem.

Note: I don't want the distance I need coordinates between two points to simulate a person on the map to move him from one point to another on the map that's why I need all coordinates to show a smooth lifelike movement.

Ali Tahir
  • 13
  • 3
  • I think you need to be very careful when defining "all coordinates". It's like asking for all floating points numbers between `(0.0, 0.0)` and `(1.0, 1.0)`. Unless specifying a precision you are looking at an infinite collection. – DeepSpace Sep 11 '19 at 14:31
  • yes, let's say I need cords from p1=(256.8526917702848,34.4067401623357) to p2=(256.8519730272503,34.406374419651) with the 0.0004 interval – Ali Tahir Sep 11 '19 at 14:35
  • So create a loop that increases each number by `0.0004` every iteration. There is not any magic algorithm here. – DeepSpace Sep 11 '19 at 14:36
  • I had tried that but when I create a path using this approach it's very slow and mostly it never finds the destination coordinates in this fraction (0.0004) – Ali Tahir Sep 11 '19 at 14:39

1 Answers1

3

This is more of a geometry problem than a python problem.

The following formula gives you all the points (x,y) between points (x1,y1) and (x2,y2):

y = (y1-y2)/(x1-x2) * (x - x1) + y1      for x in [x1, x2]

so if you want a simple python code (not the smoothest increment possible):

# your geo points
x1, y1 = 0, 0
x2, y2 = 1, 1
# the increment step (higher = faster)
STEP = 0.004

if x1 > x2:           # x2 must be the bigger one here
    x1, x2 = x2, x1
    y1, y2 = y2, y1

for i in range(int((x2-x1)/STEP) + 1):
    x = x1 + i*STEP
    y = (y1-y2)/(x1-x2) * (x - x1) + y1
    do_something(x, y)
MoaMoaK
  • 172
  • 1
  • 8