Esempio n. 1
0
        private static Polygon GetInfluencePolygon(double?possibleLatitude, double?possibleLongtitude, double radius)
        {
            if (!possibleLatitude.HasValue || !possibleLongtitude.HasValue)
            {
                return(null);
            }

            var latitude   = possibleLatitude.Value;
            var longtitude = possibleLongtitude.Value;

            Gps centre = new Gps(latitude, longtitude);

            // In metres
            double worldRadius = 6371000;

            // In metres

            Gps[] points = new Gps[20];
            CirclePoints(points, centre, worldRadius, radius);
            var polygon = new Polygon();

            polygon.Extrude                              = true;
            polygon.AltitudeMode                         = AltitudeMode.RelativeToGround;
            polygon.OuterBoundary                        = new OuterBoundary();
            polygon.OuterBoundary.LinearRing             = new LinearRing();
            polygon.OuterBoundary.LinearRing.Coordinates = new CoordinateCollection();
            points.ToList <Gps>().ForEach(g =>
            {
                polygon.OuterBoundary.LinearRing.Coordinates.Add(new SharpKml.Base.Vector(g.Latitude, g.Longtitude, 30));
            });
            // close the circle
            polygon.OuterBoundary.LinearRing.Coordinates.Add(new SharpKml.Base.Vector(points.First().Latitude, points.First().Longtitude, 30));
            return(polygon);
        }
Esempio n. 2
0
        private static void CirclePoints(Gps[] points, Gps centre, double R, double r)
        {
            int count = points.Length;

            Vector C = centre.ToUnitVector();
            double t = r / R;
            Vector K = Math.Cos(t) * C;
            double s = Math.Sin(t);

            Vector U = K.Orthogonal();
            Vector V = K.Cross(U);

            // Improve orthogonality
            U = K.Cross(V);

            for (int point = 0; point != count; ++point)
            {
                double a = 2 * Math.PI * point / count;
                Vector P = K + s * (Math.Sin(a) * U + Math.Cos(a) * V);
                points[point] = P.ToGps();
            }
        }