Rev 183 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 183 | Rev 190 | ||
---|---|---|---|
Line 12... | Line 12... | ||
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 | Sinus Funktion von Nick666 vereinfacht |
17 | Stand 28.9.2007 |
17 | Stand 30.9.2007 |
18 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
18 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
19 | */ |
19 | */ |
20 | #include "main.h" |
20 | #include "main.h" |
Line 21... | Line 21... | ||
21 | 21 | ||
22 | 22 | ||
23 | // arctan Funktion: Eingabewert x,y Rueckgabe =arctan(x,y) in grad |
23 | // arctan Funktion: Eingabewert x,y Rueckgabe =arctan(x,y) in grad |
24 | int arctan_i(long signed int x, long signed int y) |
24 | int arctan_i(long signed int x, long signed int y) |
25 | { |
25 | { |
26 | short int change_xy = 0; |
26 | short int change_xy = 0; |
27 | signed int i; |
27 | long signed int i; |
Line 28... | Line 28... | ||
28 | long signed int wert; |
28 | long signed int wert; |
29 | int return_value; |
29 | int return_value; |
Line 37... | Line 37... | ||
37 | } |
37 | } |
Line 38... | Line 38... | ||
38 | 38 | ||
Line 39... | Line 39... | ||
39 | // Quadranten ermitteln |
39 | // Quadranten ermitteln |
- | 40 | ||
40 | 41 | // Wert durch lineare Interpolation ermitteln |
|
Line 41... | Line 42... | ||
41 | // Wert durch lineare Interpolation ermitteln |
42 | if ((y == 0) && (x == 0)) wert =1; // Division durch 0 nicht erlaubt |
42 | wert= abs((x*1000)/y); |
43 | else wert= abs((x*1000)/y); |
43 | 44 | ||
44 | if (wert <=268) //0...0.0,268 entsprechend 0..15 Grad |
45 | if (wert <=268) //0...0.0,268 entsprechend 0..15 Grad |
Line 73... | Line 74... | ||
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}; |
74 | 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}; |
74 | //von Nick666, Stand 28.9.2007 |
75 | //von Nick666, Stand 28.9.2007 |
75 | // sinus Funktion: Eingabewert Winkel in Grad, Rueckgabe =sin(winkel)*1000 |
76 | // sinus Funktion: Eingabewert Winkel in Grad, Rueckgabe =sin(winkel)*1000 |
76 | signed int sin_i(signed int winkel) |
77 | signed int sin_i(signed int winkel) |
77 | { |
78 | { |
78 | short int m; |
79 | short int m,n; |
Line 79... | Line 80... | ||
79 | 80 | ||
80 | if (abs(winkel) >=360) winkel = winkel % 360; |
81 | if (abs(winkel) >=360) winkel = winkel % 360; |
81 | if (winkel < 0) |
82 | if (winkel < 0) |
82 | { |
83 | { |
83 | m = -1; |
84 | m = -1; |
84 | winkel = abs(winkel); |
85 | winkel = abs(winkel); |
85 | } |
86 | } |
- | 87 | else m = +1; |
|
86 | else m = +1; |
88 | n =1; |
87 | 89 | ||
88 | // Quadranten auswerten |
90 | // Quadranten auswerten |
89 | if ((winkel > 90 ) && (winkel <= 180)) winkel = winkel - 90; |
91 | if ((winkel > 90 ) && (winkel <= 180)) winkel = 180 - winkel; |
- | 92 | else if ((winkel > 180 ) && (winkel <= 270)) |
|
- | 93 | { |
|
- | 94 | winkel = winkel -180; |
|
- | 95 | n = -1; |
|
90 | else if ((winkel > 180 ) && (winkel <= 270)) winkel = winkel - 180; |
96 | } |
- | 97 | else if ((winkel > 270) && (winkel <= 360)) |
|
- | 98 | { |
|
- | 99 | winkel = 360 - winkel; |
|
- | 100 | n = -1; |
|
91 | else if ((winkel > 270) && (winkel <= 360)) winkel = winkel - 270; |
101 | } |
Line 92... | Line 102... | ||
92 | // else //0 - 90 Grad |
102 | // else //0 - 90 Grad |
93 | 103 | ||
94 | winkel = pgm_read_word(&pgm_sinus[winkel]); |
104 | winkel = pgm_read_word(&pgm_sinus[winkel]); |