Rev 161 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 161 | Rev 183 | ||
---|---|---|---|
Line 11... | Line 11... | ||
11 | */ |
11 | */ |
12 | /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
12 | /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
13 | Peter Muehlenbrock |
13 | Peter Muehlenbrock |
14 | Winkelfunktionen sin, cos und arctan in |
14 | Winkelfunktionen sin, cos und arctan in |
15 | brute-force Art: Sehr Schnell, nicht sonderlich genau, aber ausreichend |
15 | brute-force Art: Sehr Schnell, nicht sonderlich genau, aber ausreichend |
- | 16 | Sinus Funktion von Nick666 vereinfacht |
|
16 | Stand 20.9.2007 |
17 | Stand 28.9.2007 |
17 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
18 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
18 | */ |
19 | */ |
19 | #include "main.h" |
20 | #include "main.h" |
Line 67... | Line 68... | ||
67 | winkel = sin_i(90-winkel); |
68 | winkel = sin_i(90-winkel); |
68 | return winkel; |
69 | return winkel; |
69 | } |
70 | } |
Line -... | Line 71... | ||
- | 71 | ||
- | 72 | ||
70 | 73 | const unsigned int pgm_sinus[91] PROGMEM = {0,17,35,52,70,87,105,122,139,156,174,191,208,225,242,259,276,292,309,326,342,358,375,391,407,423,438,454,469,485,500,515,530,545,559,574,588,602,616,629,643,656,669,682,695,707,719,731,743,755,766,777,788,799,809,819,829,839,848,857,866,875,883,891,899,906,914,921,927,934,940,946,951,956,961,966,970,974,978,982,985,988,990,993,995,996,998,999,999,1000,1000}; |
|
71 | 74 | //von Nick666, Stand 28.9.2007 |
|
72 | // sinus Funktion: Eingabewert Winkel in Grad, Rueckgabe =sin(winkel)*1000 |
75 | // sinus Funktion: Eingabewert Winkel in Grad, Rueckgabe =sin(winkel)*1000 |
73 | signed int sin_i(signed int winkel) |
76 | signed int sin_i(signed int winkel) |
74 | { |
- | |
75 | short int m; |
- | |
76 | winkel = winkel % 360; |
- | |
77 | // Quadranten auswerten |
77 | { |
78 | if ((winkel >= 90 ) && (winkel <180)) |
- | |
79 | { |
- | |
80 | winkel = 180 - winkel; |
- | |
81 | m = 1; |
78 | short int m; |
82 | } |
- | |
83 | else if ((winkel >= 180 ) && (winkel <270)) |
79 | |
84 | { |
- | |
85 | winkel = winkel - 180; |
- | |
86 | m = -1; |
- | |
87 | } |
- | |
88 | else if ((winkel >= 270 ) && (winkel < 360)) |
- | |
89 | { |
- | |
90 | winkel = 360 -winkel ; |
- | |
91 | m = -1; |
- | |
92 | } |
- | |
93 | else if ((winkel < 0) && (winkel > -90)) |
- | |
94 | { |
- | |
95 | winkel = (abs(winkel)); |
- | |
96 | m = -1; |
- | |
97 | } |
80 | if (abs(winkel) >=360) winkel = winkel % 360; |
98 | else if ((winkel < -90) && (winkel > -180)) |
- | |
99 | { |
81 | if (winkel < 0) |
- | 82 | { |
|
100 | winkel = 180-(abs(winkel)); |
83 | m = -1; |
101 | m = -1; |
- | |
102 | } |
- | |
103 | else if ((winkel < -180) && (winkel > -270)) |
- | |
104 | { |
84 | winkel = abs(winkel); |
105 | winkel = (abs(winkel))-180; |
- | |
106 | m = +1; |
- | |
107 | } |
- | |
108 | else if ((winkel < -270) && (winkel > -360)) |
- | |
109 | { |
- | |
110 | winkel = 360-abs(winkel); |
- | |
111 | m = +1; |
- | |
112 | } |
- | |
113 | else |
- | |
114 | { |
- | |
115 | m = +1; |
- | |
116 | } |
85 | } |
117 | 86 | else m = +1; |
|
118 | - | ||
119 | //Aus Tabelle Werte holen |
- | |
120 | switch (winkel) |
- | |
121 | { |
- | |
122 | case 1: |
- | |
123 | winkel = 17; |
- | |
124 | break; |
- | |
125 | case 2: |
- | |
126 | winkel = 35; |
- | |
127 | break; |
- | |
128 | case 3: |
- | |
129 | winkel = 52; |
- | |
130 | break; |
- | |
131 | case 4: |
- | |
132 | winkel = 70; |
- | |
133 | break; |
- | |
134 | case 5: |
- | |
135 | winkel = 87; |
- | |
136 | break; |
- | |
137 | case 6: |
- | |
138 | winkel = 105; |
- | |
139 | break; |
- | |
140 | case 7: |
- | |
141 | winkel = 122; |
- | |
142 | break; |
- | |
143 | case 8: |
- | |
144 | winkel = 139; |
- | |
145 | break; |
- | |
146 | case 9: |
- | |
147 | winkel = 156; |
- | |
148 | break; |
- | |
149 | case 10: |
- | |
150 | winkel = 174; |
- | |
151 | break; |
87 | |
152 | case 11: |
- | |
153 | winkel = 191; |
- | |
154 | break; |
88 | // Quadranten auswerten |
155 | case 12: |
- | |
156 | winkel = 208; |
- | |
157 | break; |
- | |
158 | case 13: |
- | |
159 | winkel = 225; |
- | |
160 | break; |
- | |
161 | case 14: |
- | |
162 | winkel = 242; |
- | |
163 | break; |
- | |
164 | case 15: |
- | |
165 | winkel = 259; |
- | |
166 | break; |
- | |
167 | case 16: |
- | |
168 | winkel = 276; |
- | |
169 | break; |
- | |
170 | case 17: |
- | |
171 | winkel = 292; |
- | |
172 | break; |
- | |
173 | case 18: |
- | |
174 | winkel = 309; |
- | |
175 | break; |
- | |
176 | case 19: |
- | |
177 | winkel = 326; |
- | |
178 | break; |
- | |
179 | case 20: |
- | |
180 | winkel = 342; |
- | |
181 | break; |
- | |
182 | case 21: |
- | |
183 | winkel = 359; |
- | |
184 | break; |
- | |
185 | case 22: |
- | |
186 | winkel = 375; |
- | |
187 | break; |
- | |
188 | case 23: |
- | |
189 | winkel = 391; |
- | |
190 | break; |
- | |
191 | case 24: |
- | |
192 | winkel = 407; |
- | |
193 | break; |
- | |
194 | case 25: |
- | |
195 | winkel = 423; |
- | |
196 | break; |
- | |
197 | case 26: |
- | |
198 | winkel = 438; |
- | |
199 | break; |
- | |
200 | case 27: |
- | |
201 | winkel = 454; |
- | |
202 | break; |
- | |
203 | case 28: |
- | |
204 | winkel = 469; |
- | |
205 | break; |
- | |
206 | case 29: |
- | |
207 | winkel = 485; |
- | |
208 | break; |
- | |
209 | case 30: |
- | |
210 | winkel = 500; |
- | |
211 | break; |
- | |
212 | case 31: |
- | |
213 | winkel = 515; |
- | |
214 | break; |
- | |
215 | case 32: |
- | |
216 | winkel = 530; |
- | |
217 | break; |
- | |
218 | case 33: |
- | |
219 | winkel = 545; |
- | |
220 | break; |
- | |
221 | case 34: |
- | |
222 | winkel = 559; |
- | |
223 | break; |
- | |
224 | case 35: |
- | |
225 | winkel = 574; |
- | |
226 | break; |
- | |
227 | case 36: |
- | |
228 | winkel = 588; |
- | |
229 | break; |
89 | if ((winkel > 90 ) && (winkel <= 180)) winkel = winkel - 90; |
230 | case 37: |
- | |
231 | winkel = 602; |
- | |
232 | break; |
- | |
233 | case 38: |
- | |
234 | winkel = 616; |
- | |
235 | break; |
- | |
236 | case 39: |
- | |
237 | winkel = 630; |
- | |
238 | break; |
- | |
239 | case 40: |
- | |
240 | winkel = 643; |
- | |
241 | break; |
- | |
242 | case 41: |
- | |
243 | winkel = 656; |
- | |
244 | break; |
- | |
245 | case 42: |
- | |
246 | winkel = 682; |
- | |
247 | break; |
- | |
248 | case 43: |
- | |
249 | winkel = 682; |
- | |
250 | break; |
- | |
251 | case 44: |
- | |
252 | winkel = 695; |
- | |
253 | break; |
- | |
254 | case 45: |
- | |
255 | winkel = 707; |
- | |
256 | break; |
- | |
257 | case 46: |
- | |
258 | winkel = 719; |
- | |
259 | break; |
- | |
260 | case 47: |
- | |
261 | winkel = 731; |
- | |
262 | case 48: |
- | |
263 | winkel = 743; |
- | |
264 | break; |
- | |
265 | case 49: |
- | |
266 | winkel = 755; |
- | |
267 | break; |
- | |
268 | case 50: |
- | |
269 | winkel = 766; |
- | |
270 | break; |
- | |
271 | case 51: |
- | |
272 | winkel = 777; |
- | |
273 | break; |
- | |
274 | case 52: |
- | |
275 | winkel = 788; |
- | |
276 | break; |
- | |
277 | case 53: |
- | |
278 | winkel = 799; |
- | |
279 | break; |
- | |
280 | case 54: |
- | |
281 | winkel = 809; |
- | |
282 | break; |
- | |
283 | case 55: |
- | |
284 | winkel = 819; |
- | |
285 | break; |
- | |
286 | case 56: |
- | |
287 | winkel = 829; |
- | |
288 | break; |
- | |
289 | case 57: |
- | |
290 | winkel = 839; |
- | |
291 | break; |
- | |
292 | case 58: |
- | |
293 | winkel = 848; |
- | |
294 | break; |
- | |
295 | case 59: |
- | |
296 | winkel = 857; |
- | |
297 | break; |
- | |
298 | case 60: |
- | |
299 | winkel = 866; |
- | |
300 | break; |
- | |
301 | case 61: |
- | |
302 | winkel = 875; |
- | |
303 | break; |
- | |
304 | case 62: |
- | |
305 | winkel = 883; |
- | |
306 | break; |
- | |
307 | case 63: |
- | |
308 | winkel = 891; |
- | |
309 | break; |
- | |
310 | case 64: |
- | |
311 | winkel = 899; |
- | |
312 | break; |
90 | else if ((winkel > 180 ) && (winkel <= 270)) winkel = winkel - 180; |
313 | case 65: |
- | |
314 | winkel = 906; |
- | |
315 | break; |
- | |
316 | case 66: |
- | |
317 | winkel = 914; |
- | |
318 | break; |
- | |
319 | case 67: |
- | |
320 | winkel = 921; |
- | |
321 | break; |
- | |
322 | case 68: |
- | |
323 | winkel = 927; |
- | |
324 | break; |
- | |
325 | case 69: |
- | |
326 | winkel = 934; |
- | |
327 | break; |
- | |
328 | case 70: |
- | |
329 | winkel = 940; |
- | |
330 | break; |
- | |
331 | case 71: |
- | |
332 | winkel = 946; |
- | |
333 | break; |
- | |
334 | case 72: |
- | |
335 | winkel = 951; |
- | |
336 | break; |
- | |
337 | case 73: |
- | |
338 | winkel = 956; |
- | |
339 | break; |
- | |
340 | case 74: |
- | |
341 | winkel = 961; |
- | |
342 | break; |
- | |
343 | case 75: |
- | |
344 | winkel = 966; |
- | |
345 | break; |
- | |
346 | case 76: |
- | |
347 | winkel = 970; |
- | |
348 | break; |
- | |
349 | case 77: |
- | |
350 | winkel = 974; |
- | |
351 | break; |
- | |
352 | case 78: |
- | |
353 | winkel = 978; |
- | |
354 | break; |
- | |
355 | case 79: |
- | |
356 | winkel = 982; |
- | |
357 | break; |
- | |
358 | case 80: |
- | |
359 | winkel = 985; |
- | |
360 | break; |
- | |
361 | case 81: |
- | |
362 | winkel = 988; |
- | |
363 | break; |
- | |
364 | case 82: |
- | |
365 | winkel = 990; |
- | |
366 | break; |
- | |
367 | case 83: |
- | |
368 | winkel = 993; |
- | |
369 | break; |
- | |
370 | case 84: |
- | |
371 | winkel = 995; |
- | |
372 | break; |
- | |
373 | case 85: |
- | |
374 | winkel = 996; |
- | |
375 | break; |
- | |
376 | case 86: |
- | |
377 | winkel = 998; |
- | |
378 | break; |
- | |
379 | case 87: |
- | |
380 | winkel = 999; |
- | |
381 | break; |
- | |
382 | case 88: |
- | |
383 | winkel = 999; |
- | |
384 | break; |
- | |
385 | case 89: |
- | |
386 | winkel = 1000; |
- | |
387 | break; |
- | |
388 | case 90: |
- | |
389 | winkel = 1000; |
- | |
390 | break; |
- | |
391 | default: |
- | |
392 | winkel = 0; |
- | |
393 | break; |
- | |
394 | - | ||
Line -... | Line 91... | ||
- | 91 | else if ((winkel > 270) && (winkel <= 360)) winkel = winkel - 270; |
|
- | 92 | // else //0 - 90 Grad |
|
395 | } |
93 | |
Line 396... | Line -... | ||
396 | return (winkel*m); |
- |