forked from haraldwolff/avr-fw-modules
37 lines
704 B
C
Executable File
37 lines
704 B
C
Executable File
#include "hwo/fixpoint.h"
|
|
|
|
fixpoint_t fp_sin(fixpoint_t arc)
|
|
{
|
|
fixpoint_t a = fp_normalize_arc(arc);
|
|
|
|
if ((a == 0) || (a == fp_make(180)))
|
|
return 0;
|
|
else if (a == fp_make(90))
|
|
return fp_make(1);
|
|
else if (a == fp_make(270))
|
|
return fp_make(-1);
|
|
else
|
|
{
|
|
if (a < fp_make(90))
|
|
return fp_sin_lookup(a);
|
|
if (a < fp_make(180))
|
|
return fp_sin_lookup( fp_make(180) - a );
|
|
if (a < fp_make(270))
|
|
return - fp_sin_lookup( a - fp_make(180) );
|
|
if (a < fp_make(360))
|
|
return - fp_sin_lookup( fp_make(360) - a );
|
|
return 0;
|
|
};
|
|
};
|
|
|
|
fixpoint_t fp_cos(fixpoint_t arc)
|
|
{
|
|
return fp_sin( arc + fp_make(90));
|
|
};
|
|
|
|
fixpoint_t fp_tan(fixpoint_t arc)
|
|
{
|
|
return fp_div( fp_sin(arc), fp_cos(arc) );
|
|
};
|
|
|