In the previous section we outlined a strategy for computing the flight trajectory from departure waypoint to arrival waypoint. In this section we will show some preparatory work in Python that will be used to support the trajectory computation. This will be pretty tedious, so if you just want to see the trajectory loop and results, skip to the next section.
First, we are going to gather together all the values the trajectory computation needs for inputs. Most of these values have been established already but there are a few more we need to get.
for values marked user inputs, for now we are just entering values directly, but later on we will build an interface to get them from the user
the waypoint tolerance value is a horizontal distance; during computation, the trajectory always seeks a target waypoint; when the trajectory reaches this distance to the target waypoint, the target will update to the next waypoint;
In a later chapter we are going to show how to get winds from a weather library. For now, we are going to just assign zero wind to each sector:
We need one more value. To get the trajectory compute loop started, we need an estimate for the climb distance. This will just be an initial estimate, and the value will get refined in the compute loop.
To provide clarity later on, we will bundle some of the values into dictionaries:
We can break down our trajectory process into several sub-functions to make the code more manageable. We will list the sub-functions here and give detailed code for three of them for demonstration. The functions are:
polar_to_cartesian → convert vector from polar coordinates (brg/dist)to cartesian (x/y) coordinates
cartesian_to_polar → convert vector from cartesian to polar coordinates
normalize_direction → for any given direction value, return equivalent direction between 0 to 359°
reciprocal_direction → for any given direction value, return that value plus 180°
compute_groundspeed_and_aircraft_hdg → compute wind correction angle and groundspeed
set_initial_state_vector → set the initial state vector at the start of the compute
advance_state_vector → advance the state vector through one timestep
The functions we show below are still long, so in the future they can definitely be broken down into smaller functions, but to save time we will just show them as-is.
The functions shown in this section have been very long; to make the code more readable in the future, it would be useful to spend some time breaking them up into smaller functions
In the next section we will put all these functions together to compute a trajectory.