Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a Fast Sin() function to improve fps ? Fast sin() function?

I am rendering 500x500 points in real-time. I have to compute the position of points using atan() and sin() functions. By using atan() and sin() I am getting 24 fps (frames per second).

float thetaC = atan(value);
float h = (value) / (sin(thetaC)));

If I don't use sin() I am getting 52 fps.

and if I dont use atan() I am 30 fps.

So, the big problem is with sin(). How can I use Fast Sin version. Can I create a Look Up Table for that ? I don't have any specific values to create LUT. what can I do in this situation ?

PS: I have also tried fast sin function of ASM but not getting any difference.

Thanks.

like image 347
maxpayne Avatar asked Oct 24 '12 02:10

maxpayne


People also ask

How do you make sin in C++?

Syntax of sin() function:sin(x); Parameter(s): x – is the value of an angle in radians whose sine to be calculated. Return value: double – it returns double type value that is the sine of given angle x radians.

How does sin function work?

The sine function is defined as the ratio of the side of the triangle opposite the angle divided by the hypotenuse. This ratio can be used to solve problems involving distance or height, or if you need to know an angle measure.


1 Answers

Hang on a second....

You have a triangle, you're computing the hypoteneuse. First, you're taking atan(value) to get the angle, and then using value again with sin to compute h. So we have the scenario where one side of the triangle is 1:

   /|
h / | value
 /  |
/C__|
  1

All you really need to do is calculate h = sqrt(value*value + 1); ... But then, sqrt isn't the fastest function around either.

Perhaps I've missed the point or you've left something out. I've always used lookup tables for sin and cos, and found them to be fast. If you don't know the values ahead of time then you need to approximate, but this means a multiplication, truncation to integer (and possibly sign conversion) in order to get the array index. If you can convert your units to work in integers (effectively making your floats into fixed-point), it makes the lookup even quicker.

like image 52
paddy Avatar answered Oct 30 '22 14:10

paddy