You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
587 B
36 lines
587 B
/** |
|
* @copyright Copyright (c) 2021 Sagetech, Inc. All rights reserved. |
|
* |
|
* @file toHeading2.c |
|
* @author Jacob.Garrison |
|
* |
|
* @date Mar 2, 2021 |
|
* |
|
*/ |
|
|
|
#include <math.h> |
|
|
|
#include "sgUtil.h" |
|
|
|
/* |
|
* Documented in the header file. |
|
*/ |
|
int16_t toHeading2(double y, double x) |
|
{ |
|
int16_t heading = (toDeg(atan2(y, x)) + 0.5); |
|
heading = 360 - heading + 90; // atan is ccw 0 degrees at x = 1 and y = 0. |
|
|
|
if (heading > 360) |
|
{ |
|
heading -= 360; |
|
} |
|
else |
|
{ |
|
while (heading < 0) |
|
{ |
|
heading += 360; |
|
} |
|
} |
|
|
|
return heading; |
|
}
|
|
|