Calculate point at distance between two coordinates

62 Views Asked by At

Given two points A and B and a distance d, I'm trying to calculate a point C between A and B and at distance d from point A.

enter image description here

I was thinking on using Thales theoreme, but is there a better/simpler solution?

Cheers!

1

There are 1 best solutions below

2
On BEST ANSWER

We can parametrize the line connecting $A$ and $B$ by

$$P(t)=A+t(B-A)$$

with $t\in \mathbb R$ such that

  • $P(0)=A$
  • $P(1)=B$

then indicating with

  • $t_d=\frac d {|B-A|}$

we have that

$$C=P(t_d)=A+\frac d {|B-A|}(B-A)$$

that is in components

  • $lat_C=lat_A+\frac d {|B-A|}(lat_B-lat_aA)$
  • $lng_C=lng_A+\frac d {|B-A|}(lng_B-lng_aA)$

and

$$|B-A|=\sqrt{(lat_B-lat_A)^2+(lng_B-lng_A)^2}$$