10-07-2014, 12:03 AM
(This post was last modified: 10-07-2014, 02:01 AM by GISED_Link.)
![[Image: 586293ThundeRedResearchDepartment2.jpg]](http://img15.hostingpics.net/pics/586293ThundeRedResearchDepartment2.jpg)
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
![Confused Confused](https://forum.openredstone.org/images/smilies/confused.png)
![Confused Confused](https://forum.openredstone.org/images/smilies/confused.png)
Chapter 1 : Taylor Series
![Cool Cool](https://forum.openredstone.org/images/smilies/cool.png)
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
![Huh Huh](https://forum.openredstone.org/images/smilies/huh.png)
I skip the formula transformation, see official French topic for further precision
So, this is the final formula
![[Image: 313317fonctionapprox2.jpg]](http://img4.hostingpics.net/pics/313317fonctionapprox2.jpg)
And what this function looks like ? Let see :
![[Image: 260480Rsumdusinus.png]](http://img4.hostingpics.net/pics/260480Rsumdusinus.png)
What is the Floor ?
![Rolleyes Rolleyes](https://forum.openredstone.org/images/smilies/rolleyes.png)
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 :
![[Image: 113398Graphiquederreur.png]](http://img4.hostingpics.net/pics/113398Graphiquederreur.png)
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 :
![[Image: 44757220141001234453.png]](http://img4.hostingpics.net/pics/44757220141001234453.png)
A quick view
![[Image: 28643020141001234549.png]](http://img4.hostingpics.net/pics/28643020141001234549.png)
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 !