public Flight(TransponderData data)
 {
     TData     = data;
     Speed     = 0;
     Direction = 0;
     collision = false;
 }
Beispiel #2
0
        //Calculates the speed of a flight based on old and new TransponderData
        public double CalculateSpeed(TransponderData oldData, TransponderData newData)
        {
            int deltaX = oldData.X - newData.X;
            int deltaY = oldData.Y - newData.Y;

            var      distance = Math.Sqrt(deltaX * deltaX + deltaY * deltaY);
            TimeSpan timespan = newData.Time - oldData.Time;
            double   timedif  = timespan.TotalMilliseconds;

            return(distance / (timedif / 1000));
        }
        public void HandleNewData(TransponderData newData)
        {
            if (FlightList.Exists(f => f.TData.Tag == newData.Tag))
            {
                Flight flight = FlightList.Find(f => f.TData.Tag == newData.Tag);
                FlightList.Remove(flight);

                flight.Speed     = flightCalculator.CalculateSpeed(flight.TData, newData);
                flight.Direction = flightCalculator.CalculateDirection(flight.TData, newData);
                flight.TData     = newData;
                FlightList.Add(flight);
            }
            else
            {
                FlightList.Add(new Flight(newData));
            }
        }
Beispiel #4
0
        //Calculates the direction of a flight based on old and new TransponderData
        public double CalculateDirection(TransponderData oldData, TransponderData newData)
        {
            double deltaX = newData.X - oldData.X;
            double deltaY = newData.Y - oldData.Y;

            double toDegreeFactor = 360 / (2 * Math.PI);

            double angle = Math.Atan(deltaY / deltaX) * toDegreeFactor;

            double degree = 0;

            if (newData.X > oldData.X)
            {
                degree = 90 - angle;
            }
            else if (newData.X < oldData.X)
            {
                degree = 360 - (angle + 90);
            }
            else
            {
                if (newData.Y > oldData.Y)
                {
                    degree = 0;
                }
                else if (newData.Y < oldData.Y)
                {
                    degree = 180;
                }
                else
                {
                    degree = 0;
                }
            }

            return(degree);
        }