2
$\begingroup$

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}$$

$\endgroup$
10
  • $\begingroup$ This kind of question should be broken into two parts. First check the derivation of the equation itself. I.e., the physics and math portion. Once you are sure the math is right, then focus on whether the code faithfully reproduces the calculation. We shouldn't have to derive the equation ourselves just to check your work. :-) $\endgroup$
    – Jim
    Commented Jan 31, 2023 at 1:04
  • $\begingroup$ Do not forget that, since you are summing up flight speed and wind speed, then wind is positive when investing the aircraft from nose to tail. $\endgroup$
    – sophit
    Commented Jan 31, 2023 at 11:58
  • $\begingroup$ Maybe this can help: aviation.stackexchange.com/questions/46741/… $\endgroup$
    – fab
    Commented Jan 31, 2023 at 12:00
  • $\begingroup$ @sophit since it takes the direction from which the wind is coming, there is an "implied" 180° rotation which turns it into a subtraction, which is what I need. Ground velocity = air velocity + wind velocity, so air velocity= ground velocity - wind velocity. $\endgroup$
    – kj7rrv
    Commented Jan 31, 2023 at 14:57
  • $\begingroup$ @fab that does the opposite of what I need. I'm trying to find the airspeed of a model plane given the speed and direction of the plane from GPS and the wind speed and direction from an external source. $\endgroup$
    – kj7rrv
    Commented Jan 31, 2023 at 14:58

1 Answer 1

4
$\begingroup$

If you apply the law of cosines to the triangle formed by the vectors $\vec{A}$ (Airspeed), $\vec{W}$ (Wind) and $\vec{G_S}$ (Ground speed), where $\vec{G_S}=\vec{A}+\vec{W}$, you get:

$$|\vec{A}|=\sqrt{|\vec{G_S}|^2+|\vec{W}|^2-2|\vec{G_S}|\cdot|\vec{W}|\cdot\mathrm{cos}(\theta)}\tag{1}$$

where $\theta=\theta_{G_S}-\theta_W$.

As you yourself pointed out in the comments below, wind directions are usually reported as the direction winds originate from, not where the blow to. With that convention, the angle $\theta_W$ should be expressed as $\theta_W=\theta_W'+180$. It's easy to show that the additional $180$ can be brought out the cosine as a "-" minus sign. The final equation is therefore:

$$|\vec{A}|=\sqrt{|\vec{G_S}|^2+|\vec{W}|^2+2|\vec{G_S}|\cdot|\vec{W}|\cdot\mathrm{cos}(\theta)}\tag{2}$$

That's equivalent to yours.

$\endgroup$
4
  • $\begingroup$ My code takes the direction from which the wind is coming, so it's already negated by that. Since velocity is a vector, IIUC either speed or direction needs to be negated, and taking direction in the opposite direction suffices. Is that correct? In testing, my code seems to work. $\endgroup$
    – kj7rrv
    Commented Jan 31, 2023 at 20:14
  • $\begingroup$ "your equation has a sign that's incorrect: it should be −VWind⋅cos(θ) , not +VWind⋅cos(θ)": I've already discussed this issue with @kj7rrv, but apparently kj7rrv prefers to have +Vwind. $\endgroup$
    – sophit
    Commented Jan 31, 2023 at 20:25
  • $\begingroup$ @sophit it's not that I prefer to have +Vwind; it's that I prefer to take the wind direction in the way it's normally reported, which requires using +Vwind. $\endgroup$
    – kj7rrv
    Commented Jan 31, 2023 at 20:29
  • $\begingroup$ Ah yes, if you want to use that convention (and yes you're right, you should), then $\theta$ must be computed differently. But eventually the sign will come out of the cosine and you'll get the equation you have. I'll edit my answer to reflect this. $\endgroup$
    – fab
    Commented Jan 31, 2023 at 21:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .