trafficgen.utils¶
Utility functions that are used by several other functions.
Functions
Calculate the bearing in rad between two waypoints. |
|
Calculate the destination along the track between two waypoints when distance along the track is given. |
|
|
Calculate the distance in meter between two waypoints. |
Calculate the position along the track using waypoints. |
|
|
Calculate the position of the ship at a given time. |
Angle conversion functions. |
|
Angle conversion functions. |
|
|
Convert angle given in degrees to angle give in radians. |
|
Convert ship speed in knots to meters pr second. |
|
Convert length given in meters to length given in nautical miles. |
|
Convert ship speed in knots to meters pr second. |
|
Convert time given in minutes to time given in seconds. |
|
Convert length given in nautical miles to length given in meters. |
|
Convert angle given in radians to angle give in degrees. |
- trafficgen.utils.calculate_bearing_between_waypoints(position_prev: GeoPosition, position_next: GeoPosition) float ¶
Calculate the bearing in rad between two waypoints.
- Parameters:
position_prev (GeoPosition) – Previous waypoint {lat, lon}[rad]
position_next (GeoPosition) – Next waypoint {lat, lon}[rad]
- Returns:
bearing – Bearing between waypoints [rad]
- Return type:
float
- trafficgen.utils.calculate_destination_along_track(position_prev: GeoPosition, distance: float, bearing: float) GeoPosition ¶
Calculate the destination along the track between two waypoints when distance along the track is given.
- Parameters:
position_prev (GeoPosition) – Previous waypoint {lat, lon}[rad]
distance (float) – Distance to travel [m]
bearing (float) – Bearing from previous waypoint to next waypoint [rad]
- Returns:
destination – Destination along the track {lat, lon}[rad]
- Return type:
GeoPosition
- trafficgen.utils.calculate_distance(position_prev: GeoPosition, position_next: GeoPosition) float ¶
Calculate the distance in meter between two waypoints.
- Parameters:
position_prev (GeoPosition) – Previous waypoint {lat, lon}[rad]
position_next (GeoPosition) – Next waypoint {lat, lon}[rad]
- Returns:
distance – Distance between waypoints [m]
- Return type:
float
- trafficgen.utils.calculate_position_along_track_using_waypoints(waypoints: list[Waypoint], inital_speed: float, vector_time: float) GeoPosition ¶
Calculate the position along the track using waypoints.
The position along the track is calculated based on initial position and delta time, and constant speed and course.
- Parameters:
waypoints (list[Waypoint]) – List of ship waypoints Initial ship position {lat, lon}[rad]
inital_speed (float) – Initial ship speed [m/s]
vector_time (float) – Delta time from now to the time new position is being calculated [sec]
- Returns:
position – Estimated ship position in delta time seconds {lat, lon}[rad]
- Return type:
GeoPosition
- trafficgen.utils.calculate_position_at_certain_time(position: GeoPosition, lat_lon0: GeoPosition, sog: float, cog: float, delta_time: float) GeoPosition ¶
Calculate the position of the ship at a given time.
The calculated position is based on initial position and delta time, in addition to constant speed and course.
- Parameters:
position (GeoPosition) – Initial ship position {lat, lon} [rad]
lat_lon0 (GeoPosition) – Reference position {lat, lon} [rad]
sog (float) – Ship speed over ground[m/s]
cog (float) – Ship course over ground [rad]
delta_time (float) – Delta time from now to the time new position is being calculated [minutes]
- Returns:
position – Estimated ship position in delta time minutes {lat, lon} [rad]
- Return type:
GeoPosition
- trafficgen.utils.convert_angle_0_to_2_pi_to_minus_pi_to_pi(angle_2_pi: float) float ¶
Angle conversion functions.
Convert an angle given in the region 0 to 2*pi degrees to an angle given in the region -pi to pi degrees.
- Parameters:
angle_2_pi (float) – Angle given in the region 0 to 2pi radians
- Returns:
angle_pi – Angle given in the region -pi to pi radians
- Return type:
float
- trafficgen.utils.convert_angle_minus_pi_to_pi_to_0_to_2_pi(angle_pi: float) float ¶
Angle conversion functions.
Convert an angle given in the region -pi to pi degrees to an angle given in the region 0 to 2pi radians.
- Parameters:
angle_pi (float) – Angle given in the region -pi to pi radians
- Returns:
angle_2_pi – Angle given in the region 0 to 2pi radians
- Return type:
float
- trafficgen.utils.deg_2_rad(angle_in_degrees: float) float ¶
Convert angle given in degrees to angle give in radians.
- Parameters:
angle_in_degrees (float) – Angle given in degrees
- Returns:
angle_in_radians – Angle given in radians
- Return type:
float
- trafficgen.utils.knot_2_m_pr_s(speed_in_knot: float) float ¶
Convert ship speed in knots to meters pr second.
- Parameters:
speed_in_knot (float) – Ship speed given in knots
- Returns:
speed_in_m_pr_s – Ship speed in meters pr second
- Return type:
float
- trafficgen.utils.m_2_nm(length_in_m: float) float ¶
Convert length given in meters to length given in nautical miles.
- Parameters:
length_in_m (float) – Length given in meters
- Returns:
length_in_nm – Length given in nautical miles
- Return type:
float
- trafficgen.utils.m_pr_s_2_knot(speed_in_m_pr_s: float) float ¶
Convert ship speed in knots to meters pr second.
- Parameters:
speed_in_m_pr_s (float) – Ship speed given in meters pr second
- Returns:
speed_in_knot (float)
Ship speed in knots
- trafficgen.utils.min_2_s(time_in_min: float) float ¶
Convert time given in minutes to time given in seconds.
- Parameters:
time_in_min (float) – Time given in minutes
- Returns:
time_in_s – Time in seconds
- Return type:
float
- trafficgen.utils.nm_2_m(length_in_nm: float) float ¶
Convert length given in nautical miles to length given in meters.
- Parameters:
length_in_nm (float) – Length given in nautical miles
- Returns:
length_in_m – Length given in meters
- Return type:
float
- trafficgen.utils.rad_2_deg(angle_in_radians: float) float ¶
Convert angle given in radians to angle give in degrees.
- Parameters:
angle_in_degrees (float) – Angle given in degrees
- Returns:
angle_in_radians – Angle given in radians
- Return type:
float