Not sure if I should ask here, on Drones SE, or on Code Review SE.
Is my Python code for calculating airspeed given ground speed, ground direction, wind speed, and direction from which the wind is blowing correct? It takes directions in degrees, and the speeds can be in any units as long as they're the same; the output will be in the same unit.
import math
def find_airspeed(ground_speed, ground_direction, wind_speed, wind_direction):
angle = math.radians(wind_direction - ground_direction)
return math.sqrt(
(ground_speed + math.cos(angle) * wind_speed) ** 2
+ (math.sin(angle) * wind_speed) ** 2
)
Or, expressed as formulae:
$$\theta = (\Theta_{Wind} - \Theta_{Gnd})$$
$$AirSpeed = \sqrt{(V_{Gnd} + V_{Wind}\cdot cos(\theta)) ^2 + (V_{Wind} \cdot sin(\theta) )^2}$$