示例#1
0
        /// <summary>
        /// Computes an angular distance between two points on the unit sphere.
        /// </summary>
        /// <returns>An angular distance in radians</returns>
        public static double AngularDistance(GeoPoint p1, GeoPoint p2)
        {
            Vector3 v1 = UnitSphere.LatLonToGeocentric(p1.Phi, p1.L);
            Vector3 v2 = UnitSphere.LatLonToGeocentric(p2.Phi, p2.L);

            return(v1.Angle(v2));
        }
示例#2
0
        /// <summary>
        /// Calculates the latitude and longitude points.
        /// </summary>
        /// <param name="x">X coordinate in the plane of projection</param>
        /// <param name="y">Y-coordinate in the plane of projection</param>
        /// <param name="lat">Latitude of the</param>
        /// <param name="lon">Longitude points</param>
        public void Unproject(double x, double y, out double lat, out double lon)
        {
            Vector3 vector = _center + _xAxis * x + _yAxis * y;

            lat = UnitSphere.Latitude(vector);
            lon = UnitSphere.Longitude(vector);
        }
示例#3
0
        /// <summary>
        /// Calculates the longitude and latitude of the center
        /// of projection to the passed values ​​of latitudes and longitudes.
        /// </summary>
        /// <param name="latLonSequence">Array of real numbers that contains the latitude and longitude
        /// (to be completed in the form of a sequence of pairs: "latitude", "longitude")</param>
        /// <param name="centerLat">The output value of latitude</param>
        /// <param name="centerLon">The output value of the longitude</param>
        public static void GetCenter(double[] latLonSequence, out double centerLat, out double centerLon)
        {
            if (latLonSequence.Length % 2 != 0)
            {
                throw new ArgumentException("The array should contain an even number of elements", "values");
            }

            int    n = latLonSequence.Length / 2;
            double x = 0;
            double y = 0;
            double z = 0;

            for (int i = 0; i < latLonSequence.Length; i += 2)
            {
                Vector3 v = UnitSphere.LatLonToGeocentric(latLonSequence[i], latLonSequence[i + 1]);
                x += v.X / n;
                y += v.Y / n;
                z += v.Z / n;
            }

            Vector3 result = new Vector3(x, y, z);

            centerLat = UnitSphere.Latitude(result);
            centerLon = UnitSphere.Longitude(result);
        }
示例#4
0
        /// <summary>
        /// Calculates the coordinates of the point in the projection plane.
        /// </summary>
        /// <param name="latitude">Latitude of the</param>
        /// <param name="longitude">Longitude points</param>
        /// <param name="x">X coordinate in the plane of projection</param>
        /// <param name="y">Y-coordinate in the plane of projection</param>
        public void Project(double latitude, double longitude, out double x, out double y)
        {
            Vector3 vector = UnitSphere.LatLonToGeocentric(latitude, longitude);
            double  r      = vector * _center;

            if (r < 1e-8)
            {
                throw new ArgumentOutOfRangeException("The point is located too far from the center of projection");
            }

            vector = vector / r;

            x = vector * _xAxis;
            y = vector * _yAxis;
        }
示例#5
0
        /// <summary>
        /// Instantiates GnommonicProjection.
        /// </summary>
        /// <param name="centerLongitude">Longitude of projection center</param>
        /// <param name="centerLatitude">Latitude of projection center</param>
        public GnomonicProjection(double centerLongitude, double centerLatitude)
        {
            _center = UnitSphere.LatLonToGeocentric(centerLatitude, centerLongitude);

            double[] center = { _center.X, _center.Y, _center.Z };
            double[] vector = new double[3];

            int k = getMinEntryIndex(center);
            int j = (k + 2) % 3;
            int i = (j + 2) % 3;

            vector[i] = -center[j];
            vector[j] = center[i];
            vector[k] = 0;

            _xAxis = (new Vector3(vector[0], vector[1], vector[2])).Unitize();
            _yAxis = _center.CrossProduct(_xAxis);
        }