0

I have a geolocation represented using latitude and longitude: $({\phi_1,\lambda_1})$ and a given distance in meters $d$.

I want to find an equation for all the geolocations $({\phi_2,\lambda_2})$ that are approximately $d$ meters from the first location.

I won't be dealing with locations more than a few kilometers away from each other, and margin of error can be quite wide, so a rough approximation should be good enough.

I tried to adapt questions such as How to find a point on a line at a given distance from a given point on the same line (given the equation of the line)? and Triangulation algorithm for mobile geolocation detection , but I find it too hard to adapt to geolocation units.

I also tried to reverse the approximation equation from this reference, but could not simplify it enough:

$x=(\lambda_2-\lambda_1)\cos(\frac{\phi_1+\phi_2}{2})$

$y=\phi_2-\phi_1$

$d=\sqrt{x^2+y^2}R$

With $R$ being earth radius in meters 6371e3

Edit:

If anyone interested, javascript code based on the answer:

const toRadians = (value) => value * Math.PI / 180;

const toDegrees = (value) => value * 180 / Math.PI;

const R = 6371e3;

const getRandomLocation = ({latitude, longitude, distance}) => { const degree = Math.floor(Math.random() * 360); const noise = toRadians(degree); const phi = toRadians(latitude); const lambda = toRadians(longitude);

const randLatitude = toDegrees(phi + (distance / R) * Math.cos(noise));
const randLongitude = toDegrees(lambda + (distance / R) * (Math.sin(noise) / Math.cos(phi)));
console.info(`(${latitude},${longitude}) (${distance}m, ${degree}°)-> (${randLatitude},${randLongitude})`);
return {latitude: randLatitude, longitude: randLongitude};

};

Mugen
  • 303
  • 1
  • 8

1 Answers1

2

A cartesian equation can be found from your last formulas. I'd only substitute $\cos(\phi_1+\phi_2)/2$ with $\cos\phi_1$: $$ (\phi_2-\phi_1)^2+(\lambda_2-\lambda_1)^2\cos^2\phi_1={d^2\over R^2}. $$ If you want an explicit formula you can solve for either angle, e.g.: $$ \phi_2=\phi_1\pm\sqrt{{d^2\over R^2}-(\lambda_2-\lambda_1)^2\cos^2\phi_1}. $$ Alternatively, you can introduce a rotation angle $\theta$ and write a parametric equation: $$ \phi_2=\phi_1+{d\over R}\cos\theta; \quad \lambda_2=\lambda_1+{d\over R}{\sin\theta\over\cos\phi_1}. $$ EDIT.

The above formulas work if the angles are expressed in radians: please make the appropriate conversions if the angles are given in degrees.

Intelligenti pauca
  • 50,470
  • 4
  • 42
  • 77
  • 1
    Since the OP is (presumably) measuring latitude & longitude in degrees, it may be a good idea to make that explicit in the parametric equations. So rather than writing $\frac{d}{R}$, we have $\frac{d×360°}{2\pi R}$. With $d$ in km, that simplifies to (approximately) $\frac{d}{111.1949}$ – PM 2Ring Jun 21 '21 at 08:49
  • @PM2Ring You are right, thanks: the above formulas work if the angles are expressed in radians. I'll edit my answer. – Intelligenti pauca Jun 21 '21 at 09:12
  • Here's a Sage / Python script which plots the error of your circle equation, for a circle centred on 0° longitude, any latitude (as long as it's not too close to a pole), with radius in metres. My code uses the haversine formula for the great circle distance. As you can see, the error is very small for smallish radii. For larger circles, we'd need to use the ellipsoid distance. – PM 2Ring Jun 23 '21 at 06:50