Exemplo n.º 1
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);
        }
Exemplo n.º 2
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));
        }
Exemplo n.º 3
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);
        }