1 |
mocchiut |
1.1 |
//
|
2 |
|
|
// globals.cpp
|
3 |
|
|
//
|
4 |
|
|
#include "stdafx.h"
|
5 |
|
|
#include "globals.h"
|
6 |
|
|
|
7 |
|
|
//////////////////////////////////////////////////////////////////////////////
|
8 |
|
|
double sqr(const double x)
|
9 |
|
|
{
|
10 |
|
|
return (x * x);
|
11 |
|
|
}
|
12 |
|
|
|
13 |
|
|
//////////////////////////////////////////////////////////////////////////////
|
14 |
|
|
double Fmod2p(const double arg)
|
15 |
|
|
{
|
16 |
|
|
double modu = fmod(arg, TWOPI);
|
17 |
|
|
|
18 |
|
|
if (modu < 0.0)
|
19 |
|
|
modu += TWOPI;
|
20 |
|
|
|
21 |
|
|
return modu;
|
22 |
|
|
}
|
23 |
|
|
|
24 |
|
|
//////////////////////////////////////////////////////////////////////////////
|
25 |
|
|
// AcTan()
|
26 |
|
|
// ArcTangent of sin(x) / cos(x). The advantage of this function over arctan()
|
27 |
|
|
// is that it returns the correct quadrant of the angle.
|
28 |
|
|
double AcTan(const double sinx, const double cosx)
|
29 |
|
|
{
|
30 |
|
|
double ret;
|
31 |
|
|
|
32 |
|
|
if (cosx == 0.0)
|
33 |
|
|
{
|
34 |
|
|
if (sinx > 0.0)
|
35 |
|
|
ret = PI / 2.0;
|
36 |
|
|
else
|
37 |
|
|
ret = 3.0 * PI / 2.0;
|
38 |
|
|
}
|
39 |
|
|
else
|
40 |
|
|
{
|
41 |
|
|
if (cosx > 0.0)
|
42 |
|
|
ret = atan(sinx / cosx);
|
43 |
|
|
else
|
44 |
|
|
ret = PI + atan(sinx / cosx);
|
45 |
|
|
}
|
46 |
|
|
|
47 |
|
|
return ret;
|
48 |
|
|
}
|
49 |
|
|
|
50 |
|
|
//////////////////////////////////////////////////////////////////////////////
|
51 |
|
|
double rad2deg(const double r)
|
52 |
|
|
{
|
53 |
|
|
const double DEG_PER_RAD = 180.0 / PI;
|
54 |
|
|
return r * DEG_PER_RAD;
|
55 |
|
|
}
|
56 |
|
|
|
57 |
|
|
//////////////////////////////////////////////////////////////////////////////
|
58 |
|
|
double deg2rad(const double d)
|
59 |
|
|
{
|
60 |
|
|
const double RAD_PER_DEG = PI / 180.0;
|
61 |
|
|
return d * RAD_PER_DEG;
|
62 |
|
|
}
|
63 |
|
|
|