/// <summary>
        /// Calculates the heading on a given timestep t
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public double Heading(double t)
        {
            GeoPoint3D point1 = GeoPoint(t);
            GeoPoint3D point2 = GeoPoint(t + 1);

            return(point1.HeadingTo(point2));
        }
Exemplo n.º 2
0
        public void GeoPointHeadingToHighDlonTest()
        {
            GeoPoint3D point       = new GeoPoint3D(1.5, 2.3, 4.5);
            GeoPoint3D destination = new GeoPoint3D(850, 4500, 7800);
            double     res         = point.HeadingTo(destination);

            Assert.AreEqual(Double.NaN, res);
        }
Exemplo n.º 3
0
        public void GeoPointHeadingToTest()
        {
            GeoPoint3D point       = new GeoPoint3D(1.5, 2.3, 4.5);
            GeoPoint3D destination = new GeoPoint3D(8.5, 4.5, 7.8);
            double     res         = point.HeadingTo(destination);

            Assert.AreEqual(252.523, res, 0.001);
        }
        /// <summary>
        /// Return a string in KML format containing all updates
        /// for the contour animation at the given moment in time
        /// </summary>
        /// <returns></returns>
        public string KMLAnimationStep(int t)
        {
            if (_gradientContours.Count == 0 && _highlightedContours.Count == 0) { return ""; }

            string updateStep = "";
            Grid grid = _temporalGrid.GetGrid(t);
            List<string> visibleContours = new List<string>();
            Dictionary<int, int> occurrenceIndexes = new Dictionary<int, int>();

            foreach (Contour contour in grid.Contours)
            {
                int value = contour.Value;
                //if (!contour.IsClosed) { continue; }
                if (!_highlightedContours.Contains(value) && !_gradientContours.Contains(value)) { continue; }

                string contourId = "";
                for (int i = 0; i < _numberOfContours; i++)
                {
                    if (value == LowestContourValue + i)
                    {
                        contourId = i+"_";
                    }
                }
                int o;
                if(!occurrenceIndexes.TryGetValue(value, out o))
                {
                    o = 0;
                } else
                {
                    o++;
                }
                occurrenceIndexes[value] = o;
                contourId = contourId + o;
                

                visibleContours.Add(contourId);

                // Plot Contour
                var coordinateString = "";
                GeoPoint3D firstContourPoint = grid.GridGeoCoordinate(contour.Points[0].Location.X, contour.Points[0].Location.Y);
                GeoPoint3D contourPoint = firstContourPoint;

                foreach (ContourPoint p in contour.Points)
                {
                    contourPoint = grid.GridGeoCoordinate(p.Location.X, p.Location.Y);
                    coordinateString += contourPoint.Longitude + "," + contourPoint.Latitude + ",";
                    coordinateString += (AltitudeOffset) ? "50\n" : "0\n";
                }
                if (!contour.IsClosed)
                {
                    coordinateString += firstContourPoint.Longitude + "," + firstContourPoint.Latitude + ",";
                    coordinateString += (AltitudeOffset) ? "50\n" : "0\n";
                }

                updateStep += plotUpdate("LinearRing", coordinateString, "contour" + contourId);


                // Plot Labels
                if (_trajectory == null || !_highlightedContours.Contains(value)) { continue; }
                double pointLongitude = contourPoint.Longitude;
                double pointLatitude = contourPoint.Latitude;
                double smallestHeadingDeviation = 180;
                double desiredHeading = (_trajectory.Heading(t) + 160) % 360;
                foreach (ContourPoint p in contour.Points)
                {
                    contourPoint = grid.GridGeoCoordinate(p.Location.X, p.Location.Y);
                    double pointHeading = contourPoint.HeadingTo(_trajectory.GeoPoint(t));
                    if (pointHeading < desiredHeading && Math.Abs(pointHeading - desiredHeading) < smallestHeadingDeviation)
                    {
                        smallestHeadingDeviation = Math.Abs(pointHeading - desiredHeading);
                        pointLongitude = contourPoint.Longitude;
                        pointLatitude = contourPoint.Latitude;
                    }
                }
                if (_highlightedContours.Contains(contour.Value))
                {
                    var planeCoord = new GeoCoordinate(_trajectory.Latitude(t), _trajectory.Longitude(t));
                    var contourCoord = new GeoCoordinate(pointLatitude, pointLongitude);
                    var distance = planeCoord.GetDistanceTo(contourCoord);
                    var labelPoint = _trajectory.GeoPoint(t).MoveInDirection(distance, desiredHeading);
                    updateStep += plotUpdate("Point", labelPoint.Longitude + "," + labelPoint.Latitude + ",0", "contourPoint" + contourId);
                }
            }
            /*
            for (int i = 0; i < _numberOfContours; i++)
            {
                int value = LowestContourValue + i;
                if (!_highlightedContours.Contains(value) && !_gradientContours.Contains(value)) { continue; }
                //foreach ()
                if (!visibleContours.Contains(i))
                {
                    string longLat = (_trajectory == null) ? "0,0," : _trajectory.Longitude(t) + "," + _trajectory.Latitude(t);
                    updateStep += plotUpdate("LinearRing", longLat + ",0", "contour" + i);
                }
            }
            */
            return updateStep;
        }