16,7 → 16,7 |
// Fast arctan2 with max error of .01 rads |
// http://www.dspguru.com/comp.dsp/tricks/alg/fxdatan2.htm |
//----------------------------------------------- |
signed int arctan_i(signed int x, signed int y) |
float arctan_f(signed int x, signed int y) |
{ |
float rad,r; |
signed int angle; |
37,12 → 37,59 |
r = (x + y) / (y - x); |
rad = 0.1963*r*r*r - 0.9817*r + 2.3562; |
} |
|
angle = (180 * rad) / 3.1416; |
|
return(angle*m); |
return(rad*m); |
} |
|
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
Peter Muehlenbrock |
arctan in brute-force Art |
Stand 1.10.2007 |
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
*/ |
|
// arctan Funktion: Eingabewert x,y Rueckgabe =arctan(x,y) in grad |
int8_t arctan_i( signed int x, signed int y) |
{ |
short int change_xy = 0; |
signed int i; |
long signed int wert; |
int return_value; |
|
if ((abs(x)) > (abs(y))) // x,y Werte vertauschen damit arctan <45 grad bleibt |
{ |
change_xy = 1; |
i = x; |
x = y; |
y = i; |
} |
|
// Quadranten ermitteln |
|
// Wert durch lineare Interpolation ermitteln |
if ((y == 0) && (x == 0)) wert =1; // Division durch 0 nicht erlaubt |
else wert= abs((x*1000)/y); |
|
if (wert <=268) //0...0.0,268 entsprechend 0..15 Grad |
{ |
return_value = (signed int)((wert*100)/(268-0)*(15-0)/100) +0; |
} |
else if (wert <=578) //0,268...0.0,568 entsprechend 15..30 Grad |
{ |
return_value = (signed int)((((wert-268)*100)/(578-268)*(30-15))/100) +15; |
} |
else //0,568...1 entsprechend 30..45 Grad |
{ |
return_value = (signed int)((((wert-578)*50)/(1000-578)*(45-30))/50) +30; |
} |
|
if (change_xy == 0) return_value = 90-return_value; //Quadrant 45..90 Grad |
if ((x >= 0) && (y <0)) return_value = - return_value; |
else if ((x < 0) && (y >= 0)) return_value = - return_value; |
|
return return_value; |
} |
|
// cosinus Funktion: Eingabewert Winkel in Grad, Rueckgabe =cos(winkel)*1000 |
signed int cos_i(signed int winkel) |
{ |
51,7 → 98,7 |
} |
|
|
const unsigned int pgm_sinus[92] PROGMEM = {0,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}; |
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}; |
|
// sinus Funktion: Eingabewert Winkel in Grad, Rueckgabe =sin(winkel)*1000 |
signed int sin_i(signed int winkel) |
76,7 → 123,6 |
winkel = pgm_read_word(&pgm_sinus[winkel]); |
|
return (winkel*m*n); |
|
} |
|
|