示例#1
0
        static Line LineFromCenterAndBearing(PointD centerPoint, Double bearing, Double distance)
        {
            PointD p1 = FlatGeo.GetPoint(centerPoint, Angle.Reverse(bearing), distance / 2);
            PointD p2 = FlatGeo.GetPoint(centerPoint, bearing, distance / 2);

            return(new Line(p1, p2));
        }
示例#2
0
        public void Move(Double bearing, Double distance)
        {
            PointD np = FlatGeo.GetPoint(this, bearing, distance);

            _X = np.X;
            _Y = np.Y;
        }
示例#3
0
        public GeoPoint GetGeoPoint(PointD pixPoint)
        {
            // get a bearing to the point from our known point
            if ((pixPoint.X == this.PixPoint.X) && (pixPoint.Y == this.PixPoint.Y))
            {
                return(this.GeoPoint);
            }

            /** draw a line to get our pixel length */
            Line l1 = new Line(pixPoint, this.PixPoint);

            PointD vectorPoint = new PointD(_pixelReferencePoint.X + 100, _pixelReferencePoint.Y);
            double pixBearing  = FlatGeo.Angle(pixPoint, _pixelReferencePoint, vectorPoint).Degrees + 90;
            double pixDistance = l1.Length;

            double geoBearing  = FlatGeo.Radians((pixBearing + this.BearingDelta) % 360);
            double geoDistance = pixDistance / this.PixelsPerMeter;

            double lat = FlatGeo.Radians(this.GeoPoint.Y);
            double lon = FlatGeo.Radians(this.GeoPoint.X);

            double ddr = geoDistance / EarthGeo.EarthRadius;

            double lat2 = Math.Asin(Math.Sin(lat) * Math.Cos(ddr) + Math.Cos(lat) * Math.Sin(ddr) * Math.Cos(geoBearing));
            double lon2 = lon + Math.Atan2(Math.Sin(geoBearing) * Math.Sin(ddr) * Math.Cos(lat), Math.Cos(ddr) - Math.Sin(lat) * Math.Sin(lat2));

            lon2 = ((lon2 + Math.PI) % (2 * Math.PI)) - Math.PI;

            lat2 = FlatGeo.Degrees(lat2);
            lon2 = FlatGeo.Degrees(lon2);

            return(new GeoPoint(lat2, lon2));
        }
示例#4
0
        public Double DistanceTo(PointD to)
        {
            Double ret = Double.PositiveInfinity;

            /** make a single leg of a triangle between the remote point and one point on this line */
            Line leg = new Line(P1, to);

            /** get the interior angle */
            Double angle = FlatGeo.Angle(to, leg.P1, leg.P2).Degrees;

            if (angle >= 180)
            {
                angle -= 180;
            }

            if (angle != 0)
            {
                /** find the distance to the closest point on the line */
                ret = Math.Abs(Math.Sin(angle) * leg.Length);
            }
            else
            {
                /** the point is on the line */
                ret = 0;
            }

            return(ret);
        }
示例#5
0
        /**
         * get a point on the arc defined by 'circle' that is 'degrees' deg,
         * from 'from', in the direction of the point 'direction'
         */
        public static PointD GetPointOnArc(Circle circle, PointD from, Angle degrees, Relationship relationship, PointD referencePoint)
        {
            Line start   = new Line(circle.Center, from);
            Line refLine = new Line(circle.Center, referencePoint);

            Angle newAngle = FlatGeo.ChangeAngle(start, refLine, new Angle(degrees.Degrees * -1));

            return(GetPoint(circle.Center, newAngle.Degrees, circle.Radius));
        }
示例#6
0
        public double GetPixelBearing(PointD pt1, PointD pt2)
        {
            double retVal = FlatGeo.Degrees(Math.Atan2(pt2.Y - pt1.Y, pt2.X - pt1.X)) + 90;

            if (retVal < 0)
            {
                retVal = 360 + retVal;
            }
            return(retVal);
        }
示例#7
0
        public Angle InteriorAngle(PointD point)
        {
            LineList lines = GetLinesAdjacentTo(point);
            Angle    ret   = FlatGeo.Angle(lines[0], lines[1]);

            if (ret.Degrees > 180)
            {
                ret.Degrees = 360 - ret.Degrees;
            }
            return(ret);
        }
示例#8
0
        void RecalculateAxes()
        {
            MajorAxis = new Line(
                FlatGeo.GetPoint(_center, Angle.Reverse(_majorAxisBearing), _majorAxisLength / 2),
                FlatGeo.GetPoint(_center, _majorAxisBearing, _majorAxisLength / 2));

            Double minorAxisBearing = Angle.Add(_majorAxisBearing, 90);

            MinorAxis = new Line(
                FlatGeo.GetPoint(_center, Angle.Reverse(minorAxisBearing), _minorAxisLength / 2),
                FlatGeo.GetPoint(_center, minorAxisBearing, _minorAxisLength / 2));
        }
示例#9
0
        public PointD GetPixelPoint(GeoPoint geoPoint)
        {
            // get a bearing to the point from our known point
            double geoBearing  = EarthGeo.GetBearing(this.GeoPoint, geoPoint);
            double geoDistance = EarthGeo.GetDistance(this.GeoPoint, geoPoint);

            double pixBearing  = FlatGeo.Radians(((geoBearing + 360) - this.BearingDelta) % 360);
            double pixDistance = geoDistance * this.PixelsPerMeter;

            PointD ret = new PointD(this.PixPoint.X + (Math.Sin(pixBearing) * pixDistance), this.PixPoint.Y - (Math.Cos(pixBearing) * pixDistance));

            return(ret);
        }
示例#10
0
        static public double GetDistance(GeoPoint pt1, GeoPoint pt2)
        {
            // get the arc between the two earth points in radians
            double deltaLat  = FlatGeo.Radians(pt2.Y - pt1.Y);
            double deltaLong = FlatGeo.Radians(pt2.X - pt1.X);

            double latitudeHelix  = Math.Pow(Math.Sin(deltaLat * 0.5), 2);
            double longitudeHelix = Math.Pow(Math.Sin(deltaLong * 0.5), 2);

            double tmp = Math.Cos(FlatGeo.Radians(pt1.Y)) * Math.Cos(FlatGeo.Radians(pt2.Y));
            double rad = 2.0 * Math.Asin(Math.Sqrt(latitudeHelix + tmp * longitudeHelix));

            // Multiply the radians by the earth radius in meters for a distance measurement in meters
            return(EarthRadius * rad);
        }
示例#11
0
        public static double GetBearing(GeoPoint pt1, GeoPoint pt2)
        {
            double lat1 = FlatGeo.Radians(pt1.Y);
            double lon1 = FlatGeo.Radians(pt1.X);
            double lat2 = FlatGeo.Radians(pt2.Y);
            double lon2 = FlatGeo.Radians(pt2.X);

            double y       = Math.Sin(lon2 - lon1) * Math.Cos(lat2);
            double x       = Math.Cos(lat1) * Math.Sin(lat2) - Math.Sin(lat1) * Math.Cos(lat2) * Math.Cos(lon2 - lon1);
            double bearing = Math.Atan2(y, x);                  // bearing in radians

            double ret = (FlatGeo.Degrees(bearing) + 360) % 360;

            return(ret);
        }
示例#12
0
        void RecalculateFociAndArea()
        {
            //      __________
            //    \/ r1² * r2²
            Double fociDistance = Math.Sqrt(MajorRadius * MajorRadius - MinorRadius * MinorRadius);

            Foci = new PointD[]
            {
                FlatGeo.GetPoint(Center, Angle.Reverse(MajorAxis.Bearing), fociDistance),
                FlatGeo.GetPoint(Center, MajorAxis.Bearing, fociDistance)
            };

            Eccentricity = new Line(Foci[0], Center).Length / new Line(Foci[0], MinorAxis.P1).Length;

            Area = Math.PI * MajorRadius * MinorRadius;
        }
示例#13
0
        public static GeoPoint GetPoint(GeoPoint origin, Double bearing, Double distanceInMeters)
        {
            bearing = FlatGeo.Radians(bearing % 360);
            double ddr = distanceInMeters / EarthGeo.EarthRadius;

            double lat = FlatGeo.Radians(origin.Y);
            double lon = FlatGeo.Radians(origin.X);


            double lat2 = Math.Asin(Math.Sin(lat) * Math.Cos(ddr) + Math.Cos(lat) * Math.Sin(ddr) * Math.Cos(bearing));
            double lon2 = lon + Math.Atan2(Math.Sin(bearing) * Math.Sin(ddr) * Math.Cos(lat), Math.Cos(ddr) - Math.Sin(lat) * Math.Sin(lat2));

            lon2 = ((lon2 + Math.PI) % (2 * Math.PI)) - Math.PI;

            return(new GeoPoint(FlatGeo.Degrees(lat2), FlatGeo.Degrees(lon2)));
        }
示例#14
0
        public static bool GetIntersection(GeoLine l1, GeoLine l2, int precision, out GeoPoint intersection)
        {
            intersection = new GeoPoint();
            bool result = false;

            double A1, B1, C1;

            FlatGeo.GetLineABC(l1.ToLine(), out A1, out B1, out C1);

            double A2, B2, C2;

            FlatGeo.GetLineABC(l2.ToLine(), out A2, out B2, out C2);

            double det = A1 * B2 - A2 * B1;

            if (det != 0)
            {
                intersection = new GeoPoint((A1 * C2 - A2 * C1) / det, (B2 * C1 - B1 * C2) / det);

                bool result1 = intersection.IsWestOfOrEqualTo(EastMost(l1.P1 as GeoPoint, l1.P2 as GeoPoint), precision);
                bool result2 = intersection.IsEastOfOrEqualTo(WestMost(l1.P1 as GeoPoint, l1.P2 as GeoPoint), precision);
                bool result3 = intersection.IsWestOfOrEqualTo(EastMost(l2.P1 as GeoPoint, l2.P2 as GeoPoint), precision);
                bool result4 = intersection.IsEastOfOrEqualTo(WestMost(l2.P1 as GeoPoint, l2.P2 as GeoPoint), precision);
                bool result5 = intersection.IsSouthOfOrEqualTo(NorthMost(l1.P1 as GeoPoint, l1.P2 as GeoPoint), precision);
                bool result6 = intersection.IsNorthOfOrEqualTo(SouthMost(l1.P1 as GeoPoint, l1.P2 as GeoPoint), precision);
                bool result7 = intersection.IsSouthOfOrEqualTo(NorthMost(l2.P1 as GeoPoint, l2.P2 as GeoPoint), precision);
                bool result8 = intersection.IsNorthOfOrEqualTo(SouthMost(l2.P1 as GeoPoint, l2.P2 as GeoPoint), precision);

                if (intersection.IsWestOfOrEqualTo(EastMost(l1.P1 as GeoPoint, l1.P2 as GeoPoint), precision) && intersection.IsEastOfOrEqualTo(WestMost(l1.P1 as GeoPoint, l1.P2 as GeoPoint), precision) &&
                    intersection.IsWestOfOrEqualTo(EastMost(l2.P1 as GeoPoint, l2.P2 as GeoPoint), precision) && intersection.IsEastOfOrEqualTo(WestMost(l2.P1 as GeoPoint, l2.P2 as GeoPoint), precision) &&
                    intersection.IsSouthOfOrEqualTo(NorthMost(l1.P1 as GeoPoint, l1.P2 as GeoPoint), precision) && intersection.IsNorthOfOrEqualTo(SouthMost(l1.P1 as GeoPoint, l1.P2 as GeoPoint), precision) &&
                    intersection.IsSouthOfOrEqualTo(NorthMost(l2.P1 as GeoPoint, l2.P2 as GeoPoint), precision) && intersection.IsNorthOfOrEqualTo(SouthMost(l2.P1 as GeoPoint, l2.P2 as GeoPoint), precision))
                {
                    result = true;
                }
            }
            // else, its parallel
            return(result);
        }
示例#15
0
 public PointD GetPointAt(Double bearing, Double distance)
 {
     return(FlatGeo.GetPoint(this, bearing, distance));
 }
示例#16
0
 public PointD GetPointAt(BearingAndRange vector)
 {
     return(FlatGeo.GetPoint(this, vector.Bearing, vector.Range));
 }
示例#17
0
 public bool Intersects(Line other, out PointD intersection)
 {
     intersection = null;
     return(FlatGeo.GetIntersection(this, other, out intersection));
 }
示例#18
0
 public Line(PointD origin, Double bearing, Double distance)
     : this(origin, FlatGeo.GetPoint(origin, bearing, distance))
 {
 }