• API
• FAQ
• Tools
• Trends
• Archive
SHARE
TWEET

# Deg_Trig_Sample.h

KeithS Jun 21st, 2012 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #ifndef DEG_TRIG_H
2. #define DEG_TRIG_H
3. #include <math.h>
4.
5. #define _USE_MATH_DEFINES
8.
9. // FLOAT FUNCTIONS
10.
11. float my_atan2f_PIx2_rads(float y, float x)
12. {
16.         rads += (M_PI * 2);
18. }
19.
20. float my_atan2f_deg(float y, float x)
21. {
23.     float degs;
26.         rads += (M_PI * 2);
28.     /*if(degs < 0.0f) // Optional method
29.         degs += 360.0f;*/
30.     return degs;
31. }
32.
33. float my_cosf_deg(float deg)
34. {
35.     // It might also be a good idea to handle degs < -180ยบ
37.     float new_degs = deg;
38.     while(new_degs > 180.0f)
39.         new_degs -= 360.0f;
42. }
43.
44. float my_sinf_deg(float deg)
45. {
47.     float new_degs = deg;
48.     while(new_degs > 180.0f)
49.         new_degs -= 360.0f;
52. }
53.
54. float my_tanf_deg(float deg)
55. {
57.     float new_degs = deg;
58.     while(new_degs > 180.0f)
59.         new_degs -= 360.0f;
62. }
63.
64. // NOD - North Orientated Display
65.
66. float my_nod_atan2f_deg(float y, float x)
67. {
69.     float degs;
72.         rads += (M_PI * 2);
74.     if(degs >= 0.0f && degs <= 360.0f)
75.         degs += 90.0f;
76.     if(degs > 360.0f)
77.         degs -= 360.0f;
78.
79.     return degs;
80. }
81.
82. float my_nod_cosf_deg(float deg)
83. {
85.     float new_degs = deg;
86.     new_degs -= 90;
87.     while(new_degs > 180.0f)
88.         new_degs -= 360.0f;
91. }
92.
93. float my_nod_sinf_deg(float deg)
94. {
96.     float new_degs = deg;
97.     new_degs -= 90;
98.     while(new_degs > 180.0f)
99.         new_degs -= 360.0f;
102. }
103.
104. // DOUBLE FUNCTIONS (not overloaded)
105.
106. double my_atan2d_PIx2_rads(double y, double x)
107. {
111.         rads += (M_PI * 2);
113. }
114.
115. double my_atan2d_deg(double y, double x)
116. {
118.     double degs;
121.         rads += (M_PI * 2);
123.     /*if(degs < 0.0f) // Optional method
124.         degs += 360.0f;*/
125.     return degs;
126. }
127.
128. double my_cosd_deg(double deg)
129. {
131.     double new_degs = deg;
132.     while(new_degs > 180.0f)
133.         new_degs -= 360.0f;
136. }
137.
138. double my_sind_deg(double deg)
139. {
141.     double new_degs = deg;
142.     while(new_degs > 180.0f)
143.         new_degs -= 360.0f;
146. }
147.
148. double my_tand_deg(double deg)
149. {
151.     double new_degs = deg;
152.     while(new_degs > 180.0f)
153.         new_degs -= 360.0f;
156. }
157.
158. // NOD - North Orientated Display
159.
160. double my_nod_atan2d_deg(double y, double x)
161. {
163.     double degs;
166.         rads += (M_PI * 2);
168.     if(degs >= 0.0f && degs <= 360.0f)
169.         degs += 90.0f;
170.     if(degs > 360.0f)
171.         degs -= 360.0f;
172.
173.     return degs;
174. }
175.
176. double my_nod_cosd_deg(double deg)
177. {
179.     double new_degs = deg;
180.     new_degs -= 90;
181.     while(new_degs > 180.0f)
182.         new_degs -= 360.0f;
185. }
186.
187. double my_nod_sind_deg(double deg)
188. {