-
Notifications
You must be signed in to change notification settings - Fork 12
/
trigutil.c
68 lines (56 loc) · 1.19 KB
/
trigutil.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*=======================================================================
solunar
trigutil.c
Convenience functions for doing trig in degrees
(c)2005-2012 Kevin Boone
=======================================================================*/
#include <math.h>
#include "trigutil.h"
/**
sin of an angle in degrees
*/
double sinDeg (double deg)
{
return sin (deg * 2.0 * M_PI / 360.0);
}
/**
acos of an angle, result in degrees
*/
double acosDeg (double x)
{
return acos (x) * 360.0 / (2 * M_PI);
}
/**
asin of an angle, result in degrees
*/
double asinDeg (double x)
{
return asin (x) * 360.0 / (2 * M_PI);
}
/**
tan of an angle in degrees
*/
double tanDeg (double deg)
{
return tan (deg * 2.0 * M_PI / 360.0);
}
/**
cos of an angle in degrees
*/
double cosDeg (double deg)
{
return cos (deg * 2.0 * M_PI / 360.0);
}
/**
atan2 of an angle, result in degrees
*/
double atan2Deg (double x, double y)
{
return atan2 (x, y) * 360.0 / (2 * M_PI);
}
/* Reduce an angle to the range 0-360 degrees */
double fixAngle (double angle)
{
double result = angle - 360.0 * (floor(angle / 360.0));
return result;
}