[R-sig-Geo] Determining a coordinate given another coordinate, a great circle distance, and an angle

Harry Kim harryk at cal.berkeley.edu
Thu Oct 8 08:29:56 CEST 2009


Hi Robert,

       Thank you so much! I just tested the code and it works
beautifully. This is exactly what I wanted to do. I had  a feeling
that it could be calculated analytically but I kept messing up my
calculations.

Thanks again!
Harry

On Wed, Oct 7, 2009 at 10:47 AM, Robert J. Hijmans <r.hijmans at gmail.com> wrote:
> Harry, I think you are after something like the function below (I did not
> test it much). Robert
> # based on code at http://www.movable-type.co.uk/scripts/latlong.html
> # © 2002-2009 Chris Veness
> # license: LPGL; without any warranty express or implied
> # R version by R Hijmans
> # calculate destination point given start point, initial bearing (deg) and
> distance (km)
> #   see http://williams.best.vwh.net/avform.htm#LL
> destPoint <- function(lon, lat, bearing, d, dms=FALSE, R=6378137) {
> # bearing in degrees
> # d in meters
> # R=earth's mean radius in m
> RadDeg <- pi / 180
>
> lat1 = lat * RadDeg
> lon1 = lon * RadDeg
> brng = bearing * RadDeg
> lat2 <- asin( sin(lat1) * cos(d/R) + cos(lat1) * sin(d/R) * cos(brng) )
> lon2 <- lon1 + atan2(sin(brng) * sin(d/R) * cos(lat1), cos(d/R) - sin(lat1)
> * sin(lat2))
> lon2 <- (lon2 + pi) %% ( 2 * pi) - pi; # normalise to -180...+180
> if (is.nan(lat2) | is.nan(lon2)) return(NULL)
> return ( (cbind(lon2, lat2)) / RadDeg )
> }
> destPoint(35, 25, 30, 100000)
>
>
>
>
>
> On Tue, Oct 6, 2009 at 10:22 AM, Harry Kim <harryk at cal.berkeley.edu> wrote:
>>
>> Dear R-sig-geoers,
>>
>>      I am stuck with a problem and i was hoping if you could help me.
>> Suppose i am given a coordinate in lat/long (say 25 lat 35 long) and a
>> great circle distance (say 10km). Also assume that i am given an angle
>> with respect to latitude (an angle from the x-axis say 30 degrees).
>> What would be the best way to determine a coordinate 10kms away from
>> 25 lat 35 long with a given angle (30 degrees)?
>>
>>     I think in euclidean space, I can use tangent of the given angle
>> and combine with the Pythagorean theorem to find the target
>> coordinate.
>>
>> Thank you very much in advance,
>> Harry
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at stat.math.ethz.ch
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
>



More information about the R-sig-Geo mailing list