Rev 153 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 153 | Rev 155 | ||
---|---|---|---|
Line 14... | Line 14... | ||
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 | Stand 11.9.2007 |
16 | Stand 11.9.2007 |
17 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
17 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
18 | */ |
18 | */ |
- | 19 | #include "main.h" |
|
- | 20 | ||
Line 19... | Line 21... | ||
19 | 21 | ||
20 | // arctan Funktion: Eingabewert x,y Rueckgabe =arctan(x,y) in grad |
22 | // arctan Funktion: Eingabewert x,y Rueckgabe =arctan(x,y) in grad |
21 | signed int arctan_i(signed int x, signed int y) |
23 | int arctan_i(long signed int x, long signed int y) |
22 | { |
24 | { |
23 | short int sign = 0; |
25 | short int change_xy = 0; |
- | 26 | signed int i; |
|
- | 27 | long signed int wert; |
|
Line 24... | Line 28... | ||
24 | signed int i; |
28 | int return_value; |
25 | 29 | ||
26 | if (y > x) // x,y Werte vertauschen |
30 | if ((abs(x)) > (abs(y))) // x,y Werte vertauschen damit arctan <45 grad bleibt |
27 | { |
31 | { |
28 | sign = 1; |
32 | change_xy = 1; |
29 | i = x; |
33 | i = x; |
30 | x = y; |
34 | x = y; |
- | 35 | y = i; |
|
- | 36 | } |
|
- | 37 | ||
- | 38 | // Quadranten ermitteln |
|
- | 39 | ||
- | 40 | // Wert durch lineare Interpolation ermitteln |
|
- | 41 | wert= abs((x*1000)/y); |
|
- | 42 | ||
- | 43 | if (wert <=268) //0...0.0,268 entsprechend 0..15 Grad |
|
- | 44 | { |
|
- | 45 | return_value = (int)((wert*100)/(268-0)*(15-0)/100) +0; |
|
- | 46 | } |
|
- | 47 | else if (wert <=578) //0,268...0.0,568 entsprechend 15..30 Grad |
|
- | 48 | { |
|
- | 49 | return_value = (int)((((wert-268)*100)/(578-268)*(30-15))/100) +15; |
|
- | 50 | } |
|
- | 51 | else //0,568...1 entsprechend 30..45 Grad |
|
- | 52 | { |
|
- | 53 | return_value = (int)((((wert-578)*50)/(1000-578)*(45-30))/50) +30; |
|
- | 54 | } |
|
- | 55 | ||
- | 56 | if (change_xy > 0) return_value = 90-return_value; //Quadrant 45..90 Grad |
|
Line -... | Line 57... | ||
- | 57 | if ((x > 0) && (y <0)) return_value = - return_value; |
|
31 | y = i; |
58 | else if ((x < 0) && (y > 0)) return_value = - return_value; |
Line 32... | Line 59... | ||
32 | } |
59 | |
33 | 60 | return return_value; |