src/AircraftTrajectories/Models/Optimisation/FlightSimulator.cs
/// <summary>
/// Check whether we reached the end of a straight segment
/// </summary>
Check whether we reached the end of a straight segment
Check whether we reached the end of a straight segment
protected void CheckStraightEnd()
        {
            var currentPoint = new Point3D(_x, _y, 0, CoordinateUnit.metric);
            if (_segmentIndex == _numberOfSegments)
            {
                if (currentPoint.DistanceTo(_segmentStartPoint) >= _endPoint.DistanceTo(_segmentStartPoint))
                {
                    Log("Reached end of segment" + _segmentIndex + " (straight) X:" + _x + " Y:" + _y + " Heading:" + _heading * 180 / Math.PI);
                    _vertical_state = VERTICAL_STATE.END;
                }
            }
            else
            {
                if (_segmentIndex == _numberOfSegments - 2 && 
                    currentPoint.DistanceTo(_endPoint)/2 < _aircraft.MinimumTurnRadius(_aircraft.VMax))
                {
                    Log("Continue X:"+_x);
                    return;
                }
                if (currentPoint.DistanceTo(_segmentStartPoint) >= Interpolate(0, MAX_SEGMENT_LENGTH, Setting(2)))
                {
                    Log("Reached end of segment" + _segmentIndex + " (straight) X:"+_x + " Y:"+_y + " Heading:"+_heading*180/Math.PI);
                    _horizontal_state = HORIZONTAL_STATE.TURN;
                    _segmentStartHeading = _heading;
                    _segmentIndex++;
                }
            }
        }
protected void CheckStraightEnd ( ) { var currentPoint = new Point3D ( _x , _y , 0 , CoordinateUnit . metric ) ; if ( _segmentIndex == _numberOfSegments ) { if ( currentPoint . DistanceTo ( _segmentStartPoint ) >= _endPoint . DistanceTo ( _segmentStartPoint ) ) { Log ( " " + _segmentIndex + " " + _x + " " + _y + " " + _heading * 180 / Math . PI ) ; _vertical_state = VERTICAL_STATE . END ; } } else { if ( _segmentIndex == _numberOfSegments - 2 && currentPoint . DistanceTo ( _endPoint ) / 2 < _aircraft . MinimumTurnRadius ( _aircraft . VMax ) ) { Log ( " " + _x ) ; return ; } if ( currentPoint . DistanceTo ( _segmentStartPoint ) >= Interpolate ( 0 , MAX_SEGMENT_LENGTH , Setting ( 2 ) ) ) { Log ( " " + _segmentIndex + " " + _x + " " + _y + " " + _heading * 180 / Math . PI ) ; _horizontal_state = HORIZONTAL_STATE . TURN ; _segmentStartHeading = _heading ; _segmentIndex ++ ; } } }
Check whether we reached the end of a straight segment
Check whether we reached the end of a straight segment
// At the last straight segment, quit the optimisation when we reach the endpoint // At the second last straight segment,  // continue flying as long as we cannot reach the endpoint with a minimum radius turn in less than a 180degree turn // Switch from flying straight to a turn if we reach beyond the given segment length