zaterdag 20 april 2019

faster sinus

https://gamedev.stackexchange.com/questions/4779/is-there-a-faster-sine-function
https://web.archive.org/web/20100613230051/http://www.devmaster.net/forums/showthread.php?t=5784

float Globals::SinusPrecision(float x) {
    // high precision sine
    float sin;

    //always wrap input angle to -PI..PI
    if (x < -3.14159265f) {
        x += 6.28318531f;
    }
    else {
        if (x > 3.14159265f) {
            x -= 6.28318531f;
        }
    }

    if (x < -3.14159265f || x > 3.14159265f) {
        int w = 1;
    }

    if (x < 0)
    {
        sin = 1.27323954f * x + .405284735f * x * x;

        if (sin < 0)
            sin = .225 * (sin * -sin - sin) + sin;
        else
            sin = .225 * (sin * sin - sin) + sin;
    }
    else
    {
        sin = 1.27323954f * x - 0.405284735f * x * x;

        if (sin < 0)
            sin = .225f * (sin * -sin - sin) + sin;
        else
            sin = .225f * (sin * sin - sin) + sin;
    }

    return sin;
}
Of deze http://web.archive.org/web/20110925033606/http://lab.polygonal.de/2007/07/18/fast-and-accurate-sinecosine-approximation/

Geen opmerkingen:

Een reactie posten