Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="startAbsolutePosition">Absolute position where the contact is plotted from</param>
        /// <param name="contactType"></param>
        /// <param name="polarCoord">Bearing and range from absolute position for the new contact</param>
        /// <param name="heading"></param>
        /// <param name="speed"></param>
        /// <param name="altitude"></param>
        /// <returns></returns>
        public IReferencePoint CreateContactAtPolarCoordinate(PointF startAbsolutePosition, ContactTypes contactType, PolarCoordinate polarCoord, double heading = 0.00, double speed = 0.00, double altitude = 0.00)
        {
            var relativePosition    = startAbsolutePosition.GetRelativePosition(RadarReceiver.ViewPortExtent);
            var newRelativePosition = CoordinateConverter.CalculatePointFromDegrees(relativePosition, polarCoord, CoordinateConverter.ROUND_DIGITS);
            var newAbsolutePosition = newRelativePosition.GetAbsolutePosition(RadarReceiver.ViewPortExtent);

            return(CreateContactAtPoint(newAbsolutePosition, contactType, heading, speed, altitude));
        }
        /// <summary>
        /// Draws a line showing the course of the contact that is the equivalent of how far it will travel in VelocityVectorTime seconds
        /// </summary>
        public void DrawVelocityVector()
        {
            // Based on the course and speed calculate the distance in VelocityVectorTime seconds
            // Get the new position based on course and distance traveled
            // Now calculate the contacts movement in that timespan
            var milesPerSecond = (Contact.Speed / SECONDS_PER_HOUR);
            var distance       = VelocityVectorTime * milesPerSecond * VELOCITY_VECTOR_FACTOR;
            // Calculate the position after the distance moved in bearing and distance from the current relative position
            var newPos = CoordinateConverter.CalculatePointFromDegrees(Contact.RelativePosition, new PolarCoordinate(Contact.Heading, distance), CoordinateConverter.ROUND_DIGITS);

            // Draw a line from the current absolute position to the newly estimated position of the contact
            GraphicsContext.DrawLine(Pens.Green, Contact.Position, newPos.GetAbsolutePosition(Contact.DetectedBy.ViewPortExtent));
        }
Пример #3
0
        public void TestEnsureThatOffsetIsCalculatedCorrectly()
        {
            // ARRANGE
            // Start with relative position
            var startOffset    = new PointF(-1, 0);
            var offsetPosition = new PolarCoordinate(90.00, 1);
            var expectedResult = new PointF(0F, 0F);

            // ACT
            var actual = CoordinateConverter.CalculatePointFromDegrees(startOffset, offsetPosition, 3);

            // ASSERT
            Assert.AreEqual(expectedResult, actual);
        }
        public void TestOffsetConversionAt135Degrees()
        {
            // ARRANGE
            var expectedResult    = new PointF(7.77810669F, -7.77810669F);
            var expectedAbsResult = new PointF(131.7781F, 131.7781F);
            var startPoint        = new PointF(.70710678F, -.70710678F);

            // ACT
            var actualResult = CoordinateConverter.CalculatePointFromDegrees(startPoint, new PolarCoordinate(135, 10), 3);

            // ASSERT
            Assert.AreEqual(expectedResult, actualResult);
            Assert.AreEqual(expectedAbsResult, actualResult.GetAbsolutePosition(ViewPortExtent));
        }
Пример #5
0
        public void TestEnsureThatPlots10MilesEastOfAreCorrectRelativeToBullsEye()
        {
            // ARRANGE
            // Get Position of bullseye in relative coordinates
            var bullsEyeRelative = BullsEyeAbsolute.GetRelativePosition(ViewPortExtent);
            // We are going to plot at 90° 1 unit relative to BullsEye
            var offsetPosition = new PolarCoordinate(90.00, 10);
            var expectedResult = BullsEyeAbsolute.Offset(new PointF(10.0F, 0.0F), CoordinateConverter.ROUND_DIGITS);

            // ACT
            var newRelativePosition = CoordinateConverter.CalculatePointFromDegrees(bullsEyeRelative, offsetPosition, 3);
            var actual = newRelativePosition.GetAbsolutePosition(ViewPortExtent);

            // ASSERT
            Assert.AreEqual(expectedResult, actual);
        }
Пример #6
0
        protected override void DefaultProcessing()
        {
            //int modProcess = 20;

            var previousPositions = new SortedList <long, PointF>();

            while (_processThreadRunning)
            {
                if (Speed > 0)
                {
                    // Plot new position based on course
                    // We know that 10 seconds have passed so we have to calculate the new position and plot it
                    // Get the duration since the last update and set the LastUpdate
                    var timeSinceLastUpdate = DateTime.UtcNow - LastUpdate;
                    LastUpdate = DateTime.UtcNow;
                    // Now calculate the contacts movement in that timespan
                    var distance = timeSinceLastUpdate.TotalSeconds * (Speed / SECONDS_PER_HOUR);
                    // Get the new position based on course and distance traveled
                    var newPos    = CoordinateConverter.CalculatePointFromDegrees(RelativePosition, new PolarCoordinate(Heading, distance), CoordinateConverter.ROUND_DIGITS);
                    var newAbsPos = newPos.GetAbsolutePosition(DetectedBy.ViewPortExtent);
                    // Create Region and add the previous window to it
                    var oldRectPos = DetectionWindow;
                    // Set the new Position
                    Position = newAbsPos;
                    // Add the new position to the Region
                    var newRectPos    = DetectionWindow;
                    var rectangleList = new List <RectangleF>();
                    rectangleList.AddRange(new List <RectangleF>()
                    {
                        oldRectPos, newRectPos
                    });
                    // Notify the ISensor to repaint
                    ReferencePointChanged?.Invoke(this, new ReferencePointChangedEventArgs(rectangleList, UpdateEventTypes.PositionChange, nameof(Position)));
                    Thread.Sleep(CustomUpdateDuration ?? DEFAULT_UPDATE_MILISECONDS);
                }
            }

            Logger.Info($"{this} has stopped processing");
        }
 public static PointF GetPoint(this PolarCoordinate polarCoord, PointF offset, int roundingDigits)
 {
     return(CoordinateConverter.CalculatePointFromDegrees(offset, polarCoord, roundingDigits));
 }