Latitude and longitude of points on a line

3.7k Views Asked by At

How could you get the latitude and longitude of four points (equal distance apart) on a line from $(27,-82)$ to $(28,-81)$? The four points should split the line into 5 parts.

enter image description here

4

There are 4 best solutions below

0
On BEST ANSWER

Given the latitudes of two points, $\beta_1$ and $\beta_2$, and their difference in longitude, $\Delta\lambda=\lambda_2-\lambda_1$, compute $\delta\in[0,\pi]$ with $$ \cos(\delta)=\sin(\beta_1)\sin(\beta_2)+\cos(\beta_1)\cos(\beta_2)\cos(\Delta\lambda)\tag{1} $$ Then compute $\alpha$ using $$ \tan(\alpha/2)=\frac{\sin(\Delta\lambda)\cos(\beta_1)\cos(\beta_2)}{\sin{\beta_2}-\sin(\delta-\beta_1)}\tag{2} $$

spherical triangles, honest

After computing $\delta$ and $\alpha$, compute $\beta'\in[-\frac{\pi}{2},\frac{\pi}{2}]$ with $$ \sin(\beta')=\sin(\beta_1)\cos(k\delta/5)+\cos(\beta_1)\sin(k\delta/5)\cos(\alpha)\tag{3} $$ Then compute $\Delta\lambda'=\lambda'-\lambda_1$ using $$ \tan(\Delta\lambda'/2)=\frac{\sin(k\delta/5)\sin(\alpha)\cos(\beta_1)}{\cos(k\delta/5)+\cos(\beta_1+\beta')}\tag{4} $$ Where $k$ in $(3)$ and $(4)$ ranges in $\{1,2,3,4\}$.

2
On

The simplest is to plot $(27,-82)$ and $(28,-81)$ on your map using whatever projection you have, split the difference in pixel count into five, and plot the points that produces. That will produce a straight line on your display, which may be what you want. If you want something else, you have to define what route you want. It could be a great circle, which is the shortest distance. It could be the rhumb line, which maintains a constant bearing. Or it could be some others.

1
On

You could proceed as follows:

  1. Compute the distance $D$ between the two lat/lng points $P_1, P_2$ along the great circle.

  2. Compute the heading (bearing) $h$ of the great circle through $P_1, P_2$.

  3. Compute any point $P$ on the great circle between the two lat/lng points $P_1, P_2$, given the heading $h$ and the distance $d$ between $P_1$ and $P$, e.g. $d(n)=n D/5, n = 1..4$, in your case.

You will find formulae for all these computations on the Web, e.g. in the very good page Calculate distance, bearing and more between Latitude/Longitude points by Chris Veness.

ADDITION. I see that you included a Google Maps example. If you use Google Maps API v3, then everything is very easy:

(0) Include the Geometry library into your Web page for Spherical Computations:

<script type="text/javascript" 
    src="http://maps.googleapis.com/maps/api/js?libraries=geometry&sensor=false">
    var g = google.maps.geometry.spherical; 
</script>

(1) Use var D = g.computeDistanceBetween(P1, P2); to compute the distance D between the two points.

(2) Use var heading = g.computeHeading(P1, P2); to compute the heading.

(3) Use var point = g.computeOffset(P1, D/5, heading); to compute the point at the distance D/5 from P1 along the great circle line P1 -> P2. Similarly for the other dividing points.

1
On

Is the answer not simply found by changing each coordinate each time by a fifth of the difference in each of the lat and long elements.

(27, -82) (27.2, -81.8) (27.4, -81.6) (27.6, -81.4) (27.8, -81.2) (28, -81)