elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Entrar al Canal Oficial Telegram de elhacker.net


  Mostrar Temas
Páginas: [1]
1  Programación / Programación C/C++ / Necesito funciones personalizadas de math en: 29 Septiembre 2013, 04:43 am
Hola y gracias a todos por leer mi tema, necesito algunas funciones de trigonometría pero personalizadas, no quiero las de math.h , sino unas personalizadas

http://stackoverflow.com/questions/11261170/c-and-maths-fast-approximation-of-a-trigonometric-function
http://www.nongnu.org/avr-libc/user-manual/group__avr__math.html
http://arduino.cc/es/Reference/Libraries
http://blog.oscarliang.net/enhanced-arduino-c-custom-math-library/

Código:
float __cdecl SIN_ID(int deg){

    float result = 0;
    int sign = 1;
    if (deg < 0){
        deg = -deg;
        sign = -1;
    }
    while (deg>=3600)
        deg -= 3600;
    // 0 and 90 degrees.
    if((deg >= 0) && (deg <= 900))
        result = SIN_TABLE[deg / 5];
    // 90 and 180 degrees.
    else if((deg > 900) && (deg <= 1800))
        result = SIN_TABLE[(1800-deg) / 5];
    // 180 and 270 degrees.
    else if((deg > 1800) && (deg <= 2700))
        result = -SIN_TABLE[(deg-1800) / 5];
    // 270 and 360 degrees.
    else if((deg > 2700) && (deg <= 3600))
        result = -SIN_TABLE[(3600-deg)/5];
    return sign * result;
}

float __cdecl COS_ID(int deg){
    float result = 0;
    if (deg < 0)
        deg = -deg;
    while (deg>=3600)
        deg -= 3600;
    // 0 and 90 degrees.
    if((deg >= 0) && (deg <= 900))
        result = SIN_TABLE[(900-deg) / 5];
    // 90 and 180 degrees.
    else if((deg > 900) && (deg <= 1800))
        result = -SIN_TABLE[(deg-900) / 5];
    // 180 and 270 degrees.
    else if((deg > 1800) && (deg <= 2700))
        result = -SIN_TABLE[(2700 - deg) / 5];
    // 270 and 360 degrees.
    else if((deg >= 2700) && (deg <= 3600))
        result = SIN_TABLE[(deg - 2700) / 5];
    return result;
}

unsigned long __cdecl SQRT_ID(ulong number){
    ulong root = 0;
    ulong bit = 1UL << 30;
    // Bit starts at the highest power of four <= to input number.
    while(bit > number)  bit >>= 2;
    while(bit != 0){
        if(number >= root + bit){
            number -= (root + bit);
            root += (bit << 1);
        }
        root >>= 1;
        bit >>= 2;
    }
    return root;
}

float __cdecl ACOS_ID(float num){
    float rads = 0;
    bool negative = false;
    // Get sign of input
    if(num < 0){
        negative = true;
        num = -num;
    }
    // num between 0 and 0.9.
    if((num >= 0) && (num < 0.9))
        rads = (float)ACOS_TABLE[(int)(num*DEC4/79+0.5)] * 0.00616;
    // num between 0.9 and 0.99.
    else if ((num >= 0.9) && (num < 0.99))
        rads = (float)ACOS_TABLE[(int)((num*DEC4-9000)/8 + 0.5) + 114] * 0.00616;
    // num between 0.99 and 1.0.
    else if ((num >= 0.99) && (num <= 1))
        rads = (float)ACOS_TABLE[(int)((num*DEC4-9900)/2 + 0.5) + 227] * 0.00616;
    // Account for the negative sign if required.
    if(negative)
        rads = PI - rads;
    return rads;
}

float __cdecl ATAN2_ID(float opp, float adj){
    float hypt = SQRT_ID(adj * adj + opp * opp);
    float rad = ACOS_ID(adj/hypt);
    if(opp < 0)
        rad = -rad;
    return rad;
}

esas son las funciones que quiero usar pero necesito las tablas lookup como fue sugerido en uno de esos links que se encuentran al principio.
quisiera ayuda para poner en funcionamiento este código porque no se encuentra terminado, faltan las tablas SIN_TABLE, ACOS_TABLE y unas macro (DEC4) y en realidad no se cómo rellenar lo que falta . desde ya que agradezco cualquier respuesta para colaborar con estas funciones.
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines