## Sine and Cosine

Post your topics and discussions here that you can't find a good section for.
WhiteSnoop
Table Makers
Posts: 64
Joined: Wed May 31, 2017 11:18 pm
Reputation: 5

### Sine and Cosine

I have been struggling for hours trying to get this to work. Now I just don't know what to do anymore so maybe you guys can help me.

Math isn't my strongpoint, so little warning upfront.

[URL]https://prnt.sc/jqu042[/URL]

In the picture, I did sin(90). Even with low precision, I feel that a precision of 0.89 is pretty darn off. It should be 1 right?

For some reason, whenever I run the fsin or fcos instruction, it never seems to give me the right results.

Is there something I am missing in order to have the right values being displayed?

EDIT:

Apparently I had to do some division before I could get the right sine and cosine, not sure if it'll help anyone, but for me the value divided by '56' did the trick.

So this can be closed for all I know
Last edited by WhiteSnoop on Tue Jun 05, 2018 12:39 am, edited 3 times in total.

seikur0
Code Alchemist
Posts: 461
Joined: Sat Aug 26, 2017 10:48 am
Reputation: 201

### Sine and Cosine

The exact value to divide by is 180/pi ;) In many cases sine/cosine functions take their argument in the unit rad(ians) and not in deg(ree). So you need to convert deg to rad to put it into the function and that's done by multiplying the deg value by pi and dividing it by 180°. Google "radian" for more background.

WhiteSnoop
Table Makers
Posts: 64
Joined: Wed May 31, 2017 11:18 pm
Reputation: 5

### Sine and Cosine

Thanks seikur0, I figured this out later aswell. But still thank you for the help. I learned some maths the other day and indeed I thought I could just convert from deg haha.

What I sort of end up doing and to maybe help out others.

[CODE=nasm]

push #18 // mult

push #180 // divider

fld dword ptr [ecx+10] // rotation

fild dword ptr [esp] // divider (int to float)

fdivp // 180 / PI

fdivp // rot / divider

fsin // sine

fimul [esp+4] // sine * mult

fstp [ecx]

[/CODE]

Note: even worse was that the game already stored the values. So eventually I didn't need all this. But hey I learnt something!
Last edited by WhiteSnoop on Tue Jun 05, 2018 11:55 pm, edited 5 times in total.

SunBeam