Line data Source code
1 : /** 2 : * @copyright Copyright (c) 2021 Sagetech, Inc. All rights reserved. 3 : * 4 : * @file toHeading2.c 5 : * @author Jacob.Garrison 6 : * 7 : * @date Mar 2, 2021 8 : * 9 : */ 10 : 11 : #include <math.h> 12 : 13 : #include "sgUtil.h" 14 : 15 : /* 16 : * Documented in the header file. 17 : */ 18 4155 : int16_t toHeading2(double y, double x) 19 : { 20 4155 : int16_t heading = (toDeg(atan2(y, x)) + 0.5); 21 4155 : heading = 360 - heading + 90; // atan is ccw 0 degrees at x = 1 and y = 0. 22 : 23 4155 : if (heading > 360) 24 : { 25 3307 : heading -= 360; 26 : } 27 : else 28 : { 29 848 : while (heading < 0) 30 : { 31 0 : heading += 360; 32 : } 33 : } 34 : 35 4155 : return heading; 36 : }