How to calculate winddirection from degrees?

66 Views Asked by At

I'm reading (JSON) weatherdata into a small delphi-application. The winddirection is represented by a floatvalue from 0-360. What i want is to calculate this value into 8 directions (N,NE,E,NW,S,SE,W,SW) on the compass and show them on my applicationform as a arrowsymbol. I can use a lot of if..then to solve this, but it would be much cleaner code to just calculate it. My mathematical skills is not what they used to be, so i hope some of you coluld help me? Thanks.

1

There are 1 best solutions below

3
user3284735 On
Not deplhi but perhaps something like this?

winds=["N","NE","E","SE","S","SW","W","NW","N"]
wind_={WIND_IN_DEGREES}
index=int(round(wind_/45,0))
print(winds[index])