10-07-2014, 12:03 AM
(This post was last modified: 10-07-2014, 02:01 AM by GISED_Link.)
Calculate the sine of an angle
(in combinatorial)
Hello, it's Link !
Today (or now...), I'm going to explain you how to calculate a sine. There is algorithme for this (like CORDIC), but I will show you how to do this in combinational.
Important to know :
We give a angle, and the system return a new value : The sine. But there some trouble you have to know :
- An angle can be given in radian or in degree,
- The sine is always between -1 and 1. And, the floating number are very difficult to work with.
- The precision of the system is very important. I'll show you my result below
- The input value is between 0 and 90 (corresponding to the value in degrees)
- For the sign, us an additional circuit
- For deleting the float problem, the sine value will be given between 0 and 255 (8 bits). You have only to divide the given sine value by 255 and then you will have the true value
Mathematics
Chapter 1 : Taylor Series
for further information, look at the link.
See : Sine Series
With this series we have :
Code:
' 1 3
x - ( --- * x ) // with x in Radian !!!!
6
Chapter 2 : Magic formula
I skip the formula transformation, see official French topic for further precision
So, this is the final formula
And what this function looks like ? Let see :
What is the Floor ?
Floor() means that we take the integer portion of a division. Example: Floor(1,8) = 1 !
I choose C=76 (the best curve), and we have for precision something like that :
The yellow curve represents the error due to the 8 bits resolution. See that Sin(87)=255... So not so good.
And Minecraft with all this S*** ?
A little example :
A quick view
down : the input (here = 32), and lamp up : the result in 8 bits (here = 134) !
(and if you do ArcSin(134 / 255) you will found : 31,7 ° ! AMAZING)
You just have to divide the given value by 255 to have the truth sinus !