have "an reverse" method of GetDistance()?

Topics: General
Apr 17, 2012 at 4:54 AM

Dear Radioman, in First Place Thanks for your excelent piece of code!!! is a fantastic Control for WinForm!!

I need to know if your control have "an reverse" method of GetDistance()

In example, i like to know (or to draw) a segment of x meters, in a line defined by (new PointLatLng(Convert.ToDouble("-34.6808729522982"), Convert.ToDouble("-58.5749360918999")), (new PointLatLng(Convert.ToDouble("-34.6802310993257"), Convert.ToDouble("-58.5741984844208")));            
have some method that giving the two points and the meters, give me a resultant point that be x meters distant from the first point ?
If dont have, you happen a way for make this?? 

Thanks a lot to you or somebody that can help me with this!!!

And sorry to all for my poor english!

Apr 17, 2012 at 9:40 AM

First get the bearing between points p1 and p2:

double bearing = GMapProviders.EmptyProvider.Projection.GetBearing(p1, p2);

Then use this method:

//Radius of the Earth
        public static readonly double earthRadius = 6371d;
        /// <summary>
        /// Given a start point, initial bearing, and distance in km, this will calculate the destination point travelling along a (shortest distance) great circle arc.
        /// See: http://www.movable-type.co.uk/scripts/latlong.html 
        /// </summary>
        /// <param name="startPoint">The start point.</param>
        /// <param name="bearing">The bearing in decimal degrees.</param>
        /// <param name="distance">The distance in km</param>
        /// <returns></returns>
        public static PointLatLng GetPointLatLngFromStartPoint(PointLatLng startPoint, double bearing, double distance)
        {
            // convert distance to angular distance in radians
            distance = distance / earthRadius;
            // Convert bearing to Radians
            bearing = ToRadians(bearing);

            //Convert Degrees of startpoint to radians
            double lat1 = ToRadians(startPoint.Lat);
            double lon1 = ToRadians(startPoint.Lng);

            double lat2 = Math.Asin(Math.Sin(lat1) * Math.Cos(distance) + Math.Cos(lat1) * Math.Sin(distance) * Math.Cos(bearing));
            double lon2 = lon1 + Math.Atan2(Math.Sin(bearing) * Math.Sin(distance) * Math.Cos(lat1), Math.Cos(distance) - Math.Sin(lat1) * Math.Sin(lat2));
            //normalise to -180..+180º
            lon2 = (lon2 + 3 * Math.PI) % (2 * Math.PI) - Math.PI;  

            return new PointLatLng(ToDegrees(lat2), ToDegrees(lon2));
        }
        /// <summary>
        /// Convert given decimal degrees to radians
        /// </summary>
        /// <param name="degrees">Degrees</param>
        /// <returns>Radians</returns>
        public static double ToRadians(double degrees)
        {
            return degrees * (Math.PI / 180d);
        }

        /// <summary>
        /// Convert given radians to decimal degrees
        /// </summary>
        /// <param name="radians">Radians</param>
        /// <returns>Degrees</returns>
        public static double ToDegrees(double radians)
        {
            return radians * (180d / Math.PI);
        }

 

P.S.: Why do you Convert your doubles from a String??

 


Apr 24, 2012 at 4:24 AM

Dear Xandolph, thanks for your solution!! Is Great. I had no the bearing concept!! is that i need for this propouse!!
Thanks for help people like me, that has not yet the experience for this!!


PD_: I Convert from String because originally this code comes from a textbox!!