学位的基本风向?

sri*_*jay 3 iphone objective-c weather

有没有人在Objective C中有一些样本代码,其中风度(即180转成S(南方))转换为基本风向(N,NNE,SSE,SE等)?

Mar*_*n R 18

关于什么

- (NSString *)windDirectionFromDegrees:(float)degrees
{
    static NSArray *directions;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        // Initialize array on first call.
        directions = @[@"N", @"NNE", @"NE", @"ENE", @"E", @"ESE", @"SE", @"SSE",
                       @"S", @"SSW", @"SW", @"WSW", @"W", @"WNW", @"NW", @"NNW"];
    });

    int i = (degrees + 11.25)/22.5;
    return directions[i % 16];
}
Run Code Online (Sandbox Code Playgroud)

(我认为这degrees不是消极的.)