atan2

How to map atan2() to degrees 0-360

人盡茶涼 提交于 2019-11-27 03:05:43
atan2(y,x) has that discontinuity at 180° where it switches to -180°..0° going clockwise. How do I map the range of values to 0°..360°? here is my code: CGSize deltaPoint = CGSizeMake(endPoint.x - startPoint.x, endPoint.y - startPoint.y); float swipeBearing = atan2f(deltaPoint.height, deltaPoint.width); I'm calculating the direction of a swiping touch event given the startPoint and endPoint, both XY point structs. The code is for the iPhone but any language that supports atan2f() will do. Thanks for your help guys, with both the general solution and code. Update : I made erikkallen's answer