[GRASS-user] How to find a point on Earth d distance away from a given point?

Hi,

Sorry if this sort of questions are not discussed here. If so, I'd
appreciate it if you told me where to ask.

Given a point A (lat1, lng1) I need to find coordinates of point B
(lat2, lng2) d km away from point A.

This is basically what I want:

    http://math.stackexchange.com/questions/1026466/given-a-longitude-and-latitude-and-a-specified-distance-how-would-i-go-about-fi/1026501

But the person who answers seem to be using formula for colatitudes
(actually, the formulas seem to be identical, I don't see a
difference), and supposedly have a mistake in resulting forumla
(missing phi_a). And most importantly, I did just that (or so I
think), but it doesn't work.

I choose lat2 = lat1, dist = 10, for example, and then calculate lng2 like so:

    lng2 = lng1 + d(acos(
        (cos(dist / R) - sin(r(lat1)) * sin(r(lat1)))
        / cos(r(lat1)) * cos(r(lat1))
    ))

where R - radius of the Earth, d() converts radians to degrees, and
r() does the opposite.

Then put this all into original formula (from
http://www.movable-type.co.uk/scripts/latlong.html):

    d = acos(
        sin(r(lat1)) * sin(r(lat2))
        + cos(r(lat1)) * cos(r(lat2)) * cos(r(lng2 - lng1))
    ) * R

And get d <> 10.

What am I doing wrong? Your help is greatly appreciated.

You can experiment with it here, if you feel like it:
http://fiddle.jshell.net/LLh42xh5/3/ Click Run to rerun the script
after making changes.

Regards,
Yuri

Hi Yuri,

On Thu, Sep 8, 2016 at 11:35 AM, Yuri Kanivetsky
<yuri.kanivetsky@gmail.com> wrote:

Hi,

Sorry if this sort of questions are not discussed here. If so, I'd
appreciate it if you told me where to ask.

Given a point A (lat1, lng1) I need to find coordinates of point B
(lat2, lng2) d km away from point A.

This is basically what I want:

    http://math.stackexchange.com/questions/1026466/given-a-longitude-and-latitude-and-a-specified-distance-how-would-i-go-about-fi/1026501

While I cannot help you right away with your math, you may want to
take a look at this GRASS GIS module:

m.cogo - A simple utility for converting bearing and distance
  measurements to coordinates and vice versa. It assumes a cartesian
  coordinate system
https://grass.osgeo.org/grass72/manuals/m.cogo.html

At the bottom of the manual page you find the link to the source code.

Best,
Markus

--
Markus Neteler
http://www.mundialis.de - free data with free software
http://grass.osgeo.org
http://courses.neteler.org/blog

Hi Markus,

Thanks for your reply. But actually, my friend has pointed out at my
error. But if not that, your link would be the next the place to try
and find the answer.

In case someone will find this, here's the correct formula:

    lng1 + d(acos(
        (cos(dist / R) - sin(r(lat1)) * sin(r(lat1)))
        / (cos(r(lat1)) * cos(r(lat1)))
    ))

And a fiddle to experiment with:

http://fiddle.jshell.net/LLh42xh5/5/

Regards,
Yuri