예제 #1
0
        //----- 2nd iteration, after realising selecting the runway was not enough --------
        public int SelectOptimalRunwayDirection(List <int> runway_directions, int wind_direction)
        {
            if (runway_directions == null || runway_directions.Count == 0)
            {
                throw new System.ArgumentException("Runway selector cannot accept empty runway list");
            }

            RunwayDto SelectedRunway = new RunwayDto();

            //find the lowest value cosine for the difference between the wind angle and the runway angle

            double LowestCosine = 1.1;             //inital impossible cosine value above maximum
            int    current_winning_direction = -1; //initial impossible degree value

            for (int x = 0; x < runway_directions.Count; x++)
            {
                //candidate runway directions
                int direction          = runway_directions[x];
                int opposite_direction = (direction + 180) % 360;

                //difference between runway directions and wind direction
                int absolute_difference_a = Math.Abs(direction - wind_direction);
                int absolute_difference_b = Math.Abs(opposite_direction - wind_direction);

                double test_a = Math.Cos(absolute_difference_a * Math.PI / 180.0);
                double test_b = Math.Cos(absolute_difference_b * Math.PI / 180.0);

                if (test_a < LowestCosine)
                {
                    LowestCosine = test_a;
                    current_winning_direction = direction;
                }

                if (test_b < LowestCosine)
                {
                    LowestCosine = test_b;
                    current_winning_direction = opposite_direction;
                }
            }

            if (current_winning_direction == -1) //should always return a runway direction
            {
                throw new System.Exception("SelectOptimalRunwayDirection could not find optimal runway direction");
            }

            return(current_winning_direction);
        }
예제 #2
0
        //----- 1st iteration -------
        public int SelectRunway(List <int> runway_directions, int wind_direction)   //returns integer index with most optimal runway
        {
            if (runway_directions == null || runway_directions.Count == 0)
            {
                throw new System.ArgumentException("Runway selector cannot accept empty runway list");
            }

            RunwayDto SelectedRunway = new RunwayDto();

            //find the lowest value cosine for the difference between the wind angle and the runway angle

            double LowestCosine   = 1; //inital value max
            int    current_winner = 0;

            for (int x = 0; x < runway_directions.Count; x++)
            {
                //candidate runway directions
                int direction          = runway_directions[x];
                int opposite_direction = (direction + 180) % 360;

                //difference between runway directions and wind direction
                int absolute_difference_a = Math.Abs(direction - wind_direction);
                int absolute_difference_b = Math.Abs(opposite_direction - wind_direction);

                double test_a = Math.Cos(absolute_difference_a * Math.PI / 180.0);
                double test_b = Math.Cos(absolute_difference_b * Math.PI / 180.0);

                if (test_a < LowestCosine)
                {
                    LowestCosine   = test_a;
                    current_winner = x;
                }

                if (test_b < LowestCosine)
                {
                    LowestCosine   = test_b;
                    current_winner = x;
                }
            }

            return(current_winner);
        }