I have my own, very fast cos function:
float sine(float x)
{
const float B = 4/pi;
const float C = -4/(pi*pi);
float y = B * x + C * x * abs(x);
// const float Q = 0.775;
const float P = 0.225;
y = P * (y * abs(y) - y) + y; // Q * y + P * y * abs(y)
return y;
}
float cosine(float x)
{
return sine(x + (pi / 2));
}
But now when I profile, I see that acos() is killing the processor. I don't need intense precision. What is a fast way to calculate acos(x) Thanks.
In a right-angled triangle, the cosine of an angle (θ) is the ratio of its adjacent side to the hypotenuse. i.e., cos θ = (adjacent side) / (hypotenuse). Then by the definition of arccosine, θ = cos-1[ (adjacent side) / (hypotenuse) ] .
The arccosine is the inverse of the cosine. It's most useful when trying to find the angle measure when two sides of a triangle are known. The arccosine allows you to find the measure of an angle when you know the ratio of the adjacent side to the hypotenuse.
C acos() The acos() function returns the arc cosine (inverse cosine) of a number in radians. The acos() function takes a single argument (1 ≥ x ≥ -1), and returns the arc cosine in radians. Mathematically, acos(x) = cos-1(x) .
A simple cubic approximation, the Lagrange polynomial for x ∈ {-1, -½, 0, ½, 1}, is:
double acos(x) {
return (-0.69813170079773212 * x * x - 0.87266462599716477) * x + 1.5707963267948966;
}
It has a maximum error of about 0.18 rad.
Got spare memory? A lookup table (with interpolation, if required) is gonna be fastest.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With