Beispiel #1
0
 public void Addto(GeoLocation point)
 {
     data_list.Add(point);
 }
Beispiel #2
0
        /// <summary>
        /// Calculates the intersection point3 in degrees from point1, crs13, point2, crs23
        /// </summary>
        /// <param name="point1_deg"></param>
        /// <param name="crs13_radians"></param>
        /// <param name="point2_deg"></param>
        /// <param name="crs23_radians"></param>
        /// <returns></returns>
        public static GeoLocation GetIntersection(GeoLocation point1_deg, double crs13_radians, GeoLocation point2_deg, double crs23_radians)
        {
            double      lat1 = DegreesToRadians(point1_deg.Latitude);
            double      lon1 = DegreesToRadians(point1_deg.Longitude);
            double      lat2 = DegreesToRadians(point2_deg.Latitude);
            double      lon2 = DegreesToRadians(point2_deg.Longitude);
            double      crs12, crs21, ang1, ang2, ang3, dst13, lat3, lon3, dlon;
            GeoLocation point3 = new GeoLocation();

            double delta_lat = lat2 - lat1;
            double delta_lon = lon2 - lon1;


            //double dst12 = 2 * Math.Asin(Math.Pow(Math.Sqrt(Math.Sin((lat1 - lat2) / 2),2) + Math.Cos(lat1) * Math.Cos(lat2) * Math.Pow(Math.Sin((lon1 - lon2) / 2),2)));
            double dst12  = 2 * Math.Asin(Math.Sqrt(Math.Sin(delta_lat / 2) * Math.Sin(delta_lat / 2) + Math.Cos(lat1) * Math.Cos(lat2) * Math.Sin(delta_lon / 2) * Math.Sin(delta_lon / 2)));
            double dist12 = geolib.RadiansToDegrees(dst12) * 60 * 1.1515 * 0.8684;
            // Debug.WriteLine("dst12: " + dist12, "GetIntersection");

            double ang_a = Math.Acos((Math.Sin(lat2) - Math.Sin(lat1) * Math.Cos(dst12)) / (Math.Sin(dst12) * Math.Cos(lat1)));
            double ang_b = Math.Acos((Math.Sin(lat1) - Math.Sin(lat2) * Math.Cos(dst12)) / (Math.Sin(dst12) * Math.Cos(lat2)));

            if (Math.Sin(lon2 - lon1) > 0)
            {
                crs12 = ang_a;
                crs21 = 2 * Math.PI - ang_b;
            }
            else
            {
                crs12 = 2 * Math.PI - ang_a;
                crs21 = ang_b;
            }
            ang1 = d_mod(crs13_radians - crs12 + Math.PI, 2 * Math.PI) - Math.PI;
            ang2 = d_mod(crs21 - crs23_radians + Math.PI, 2 * Math.PI) - Math.PI;
            //Debug.WriteLine("Angle2-1-3: " + geolib.RadiansToDegrees(ang1) + " Angle1-2-3: " + geolib.RadiansToDegrees(ang2), "GetIntersection");

            if (Math.Sin(ang1) == 0 && Math.Sin(ang2) == 0)
            {
                //"infinity of intersections"
                Debug.WriteLine("ERROR: infinity of intersections found.", "GetIntersection");
                point3.Latitude = 99; //return an invalid degree to signal failure - which means lines are parallel
                return(point3);
            }
            else if ((Math.Sin(ang1) * Math.Sin(ang2)) < 0)
            {
                //"intersection ambiguous"
                Debug.WriteLine("ERROR: intersection ambiguous found.", "GetIntersection");
                point3.Latitude = 99; //return an invalid degree to signal failure  - which means lines are parallel
                return(point3);
            }
            else
            {
                ang1             = Math.Abs(ang1);
                ang2             = Math.Abs(ang2);
                ang3             = Math.Acos(-Math.Cos(ang1) * Math.Cos(ang2) + Math.Sin(ang1) * Math.Sin(ang2) * Math.Cos(dst12));
                dst13            = Math.Atan2(Math.Sin(dst12) * Math.Sin(ang1) * Math.Sin(ang2), Math.Cos(ang2) + Math.Cos(ang1) * Math.Cos(ang3));
                lat3             = Math.Asin(Math.Sin(lat1) * Math.Cos(dst13) + Math.Cos(lat1) * Math.Sin(dst13) * Math.Cos(crs13_radians));
                dlon             = Math.Atan2(Math.Sin(crs13_radians) * Math.Sin(dst13) * Math.Cos(lat1), Math.Cos(dst13) - Math.Sin(lat1) * Math.Sin(lat3));
                lon3             = d_mod(lon1 + dlon + Math.PI, 2 * Math.PI) - Math.PI;
                point3.Latitude  = RadiansToDegrees(lat3);
                point3.Longitude = RadiansToDegrees(lon3);
                //Debug.WriteLine("Lat: " + point3.Latitude + " Lon: " + point3.Longitude, "GetIntersection");
                return(point3);
            }
        }