CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/libraries/AP_ADSB/sagetech-sdk/toHeading2.c
Views: 1799
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
int16_t toHeading2(double y, double x)
19
{
20
int16_t heading = (toDeg(atan2(y, x)) + 0.5);
21
heading = 360 - heading + 90; // atan is ccw 0 degrees at x = 1 and y = 0.
22
23
if (heading > 360)
24
{
25
heading -= 360;
26
}
27
else
28
{
29
while (heading < 0)
30
{
31
heading += 360;
32
}
33
}
34
35
return heading;
36
}
37
38