示例#1
0
 public bool Contains(GeoPoint point)
 {
     return(Contains(point, DEFAULT_RAY_LENGTH));
 }
示例#2
0
 public static GeoPoint WestMost(GeoPoint p1, GeoPoint p2)
 {
     return(p1.IsWestOf(p2) ? p1 : p2);
 }
示例#3
0
 public static bool GetIntersection(GeoLine l1, GeoLine l2, out GeoPoint retPoint)
 {
     return(GetIntersection(l1, l2, EarthGeo.GeoPrecision, out retPoint));
 }
示例#4
0
        /**
         * Returns the point of intersection of two paths defined by point and bearing.
         *
         * @param   {LatLon} p1 - First point.
         * @param   {number} brng1 - Initial bearing from first point.
         * @param   {LatLon} p2 - Second point.
         * @param   {number} brng2 - Initial bearing from second point.
         * @returns {LatLon} Destination point (null if no unique intersection defined).
         *
         * @example
         *     var p1 = LatLon(51.8853, 0.2545), brng1 = 108.547;
         *     var p2 = LatLon(49.0034, 2.5735), brng2 =  32.435;
         *     var pInt = LatLon.intersection(p1, brng1, p2, brng2); // pInt.toString(): 50.9076°N, 004.5084°E
         */
        public static bool GetIntersection2(GeoPoint p1, Double brng1, GeoPoint p2, Double brng2, out GeoPoint intersection)
        {
            intersection = null;

            // see http://williams.best.vwh.net/avform.htm#Intersection
            Double φ1 = Radians(p1.Latitude);
            Double λ1 = Radians(p1.Longitude);
            Double φ2 = Radians(p2.Latitude);
            Double λ2 = Radians(p2.Longitude);
            Double θ13 = Radians(brng1);
            Double θ23 = Radians(brng2);
            Double Δφ = φ2 - φ1, Δλ = λ2 - λ1;

            Double δ12 = 2 * Math.Asin(Math.Sqrt(Math.Sin(Δφ / 2) * Math.Sin(Δφ / 2) +
                                                 Math.Cos(φ1) * Math.Cos(φ2) * Math.Sin(Δλ / 2) * Math.Sin(Δλ / 2)));

            if (δ12 != 0)               // if zero, no intersection
            {
                // initial/final bearings between points
                Double θ1 = Math.Acos((Math.Sin(φ2) - Math.Sin(φ1) * Math.Cos(δ12)) /
                                      (Math.Sin(δ12) * Math.Cos(φ1)));
                if (Double.IsNaN(θ1))
                {
                    θ1 = 0;                     // protect against rounding
                }

                Double θ2 = Math.Acos((Math.Sin(φ1) - Math.Sin(φ2) * Math.Cos(δ12)) /
                                      (Math.Sin(δ12) * Math.Cos(φ2)));

                Double θ12, θ21;
                if (Math.Sin(λ2 - λ1) > 0)
                {
                    θ12 = θ1;
                    θ21 = 2 * Math.PI - θ2;
                }
                else
                {
                    θ12 = 2 * Math.PI - θ1;
                    θ21 = θ2;
                }

                Double α1 = (θ13 - θ12 + Math.PI) % (2 * Math.PI) - Math.PI;               // angle 2-1-3
                Double α2 = (θ21 - θ23 + Math.PI) % (2 * Math.PI) - Math.PI;               // angle 1-2-3

                if (Math.Sin(α1) == 0 && Math.Sin(α2) == 0)
                {
                    // infinite intersections
                }
                else if (Math.Sin(α1) * Math.Sin(α2) < 0)
                {
                    // ambiguous intersection
                }
                else
                {
                    //α1 = Math.abs(α1);
                    //α2 = Math.abs(α2);
                    // ... Ed Williams takes abs of α1/α2, but seems to break calculation?

                    Double α3 = Math.Acos(-Math.Cos(α1) * Math.Cos(α2) +
                                          Math.Sin(α1) * Math.Sin(α2) * Math.Cos(δ12));
                    Double δ13 = Math.Atan2(Math.Sin(δ12) * Math.Sin(α1) * Math.Sin(α2),
                                            Math.Cos(α2) + Math.Cos(α1) * Math.Cos(α3));
                    Double φ3 = Math.Asin(Math.Sin(φ1) * Math.Cos(δ13) +
                                          Math.Cos(φ1) * Math.Sin(δ13) * Math.Cos(θ13));
                    Double Δλ13 = Math.Atan2(Math.Sin(θ13) * Math.Sin(δ13) * Math.Cos(φ1),
                                             Math.Cos(δ13) - Math.Sin(φ1) * Math.Sin(φ3));
                    Double λ3 = λ1 + Δλ13;
                    λ3           = (λ3 + 3 * Math.PI) % (2 * Math.PI) - Math.PI;     // normalise to -180..+180º
                    intersection = new GeoPoint(Degrees(φ3), Degrees(λ3));
                }
            }
            return(intersection != null);
        }
示例#5
0
 public static GeoPoint SouthMost(GeoPoint p1, GeoPoint p2)
 {
     return(p1.IsSouthOf(p2) ? p1 : p2);
 }
示例#6
0
        public override void Move(Double bearing, Double distance)
        {
            GeoPoint newCenter = EarthGeo.GetPoint(GeoCenter, bearing, distance);

            Move(newCenter);
        }
示例#7
0
        //public int CompareTo(object other)
        //{
        //	return PointCommon.ComparePoints(this, other, Precision);
        //}

        public bool Equals(GeoPoint other)
        {
            return(Equals(other, 0));
        }
示例#8
0
 public bool IsEastOfOrEqualTo(GeoPoint other, int precision = EarthGeo.GeoPrecision)
 {
     return(IsEastOf(other) || Longitude.EqualsAtPrecision(other.Longitude, precision));
 }
示例#9
0
 public bool IsEastOf(GeoPoint other)
 {
     return(!IsWestOf(other));
 }
示例#10
0
 public bool IsSouthOfOrEqualTo(GeoPoint other, int precision = EarthGeo.GeoPrecision)
 {
     return(IsSouthOf(other) || (Latitude.EqualsAtPrecision(other.Latitude, precision) && LatitudeCD == other.LatitudeCD));
 }
示例#11
0
 public bool IsSouthOf(GeoPoint other)
 {
     return(!IsNorthOf(other));
 }
示例#12
0
 public GeoPoint(GeoPoint point, int precision)
     : this(point.Latitude, point.Longitude)
 {
     Precision = precision;
 }
示例#13
0
 public GeoPoint(GeoPoint point)
     : this(point.Latitude, point.Longitude)
 {
 }
示例#14
0
 public virtual bool Intersects(GeoLine line, out GeoPoint intersection1, out GeoPoint intersection2, out int intersectionsCalculated)
 {
     throw new NotImplementedException();
 }
示例#15
0
        public bool Contains(GeoPoint point, Double rayLength = DEFAULT_RAY_LENGTH)
        {
            /** Use Ray-Casting Algorithm to determine if point lies within polygon */

            Double rayBearing = EarthGeo.North;
            float  insides    = 0;
            float  outsides   = 0;

            int minimumRays = 4;

            bool majority = false;

            /**
             * We will cast at least two rays and keep casting till we get a majority of
             * one or the other, or we go in a circle.
             */
            do
            {
                /**
                 * Step One:
                 *   Create a ray from our point extending outwards
                 */
                GeoPoint endPoint = EarthGeo.GetPoint(point, rayBearing, rayLength);
                GeoLine  ray      = new GeoLine(point, endPoint);

                /**
                 * Step 2
                 *   Draw line from our point in any direction (we will use North)
                 *   and count the intersections
                 */
                Double intersections = 0;
                foreach (GeoLine line in Lines)
                {
                    if (ray.Intersects(line))
                    {
                        intersections++;
                    }
                }

                /** if the intersections are even, the point is outside... if odd, it's inside */
                bool inside = (intersections % 2) != 0;

                if (inside)
                {
                    insides++;
                }
                else
                {
                    outsides++;
                }

                rayBearing = Angle.Add(rayBearing, 95);

                if (insides + outsides >= minimumRays)
                {
                    majority = insides > outsides * 2 || outsides > insides * 2;
                }
            }while(majority == false && !(insides + outsides >= 360 / 5));

            return(insides > outsides);
        }
示例#16
0
 public void Move(GeoPoint where)
 {
     m_Latitude  = where.Y;
     m_Longitude = where.X;
 }
示例#17
0
 public Line(GeoPoint p1, GeoPoint p2)
 {
     _p1 = p1.ToPointD();
     _p2 = p2.ToPointD();
     Tag = null;
 }
示例#18
0
 public GeoEllipse(GeoPoint center, Double radius)
     : this(center, radius, radius, 0)
 {
 }