How do I calculate a classic sin(x) function

Get help using Construct 2

» Fri Feb 13, 2015 10:50 am

Hi guys,

I am confused, since I would like to use a simple calculation sin(x), but it does not return the values I expect at all.

sin(1*pi*0.5) should be in my understanding (and is indeed on all calculators) 1.

If I let that calculate in construct, it gives me back an odd number: 0.0274121336

Please help me, whats going on. And why? How can be a common sin(x) function something different here?
B
8
S
3
Posts: 197
Reputation: 1,207

» Fri Feb 13, 2015 11:53 am

Looking at that wikipedia page SIN is expected to return a result in RADIANS, sin() in Construct 2 takes and returns degrees, that may be where the difference is coming from.

Using windows' calculator in scientific mode, I actually do find out the very same result: 0.0274121336 (keys : [1] [*] [PI] [*] [0.5] [=] [sin]) (calc being set in "Degrees" mode, set in "Radians" it returns 1 as well.)
New to Construct ? Where to start

Please attach a capx to any help request or bug report !
Moderator
B
307
S
126
G
99
Posts: 7,385
Reputation: 73,871

» Fri Feb 13, 2015 1:28 pm

@Kyatric True that, thanks.

To be honest, I don't like it this way too much. I still think it is most of the times way more handy the rad-way to be used as a math function...

However, most important is, it works. Thanks once again for the clearance!
B
8
S
3
Posts: 197
Reputation: 1,207

» Fri Feb 13, 2015 2:03 pm

Actually it is easy... so nothing to dislike, I just did not get it, math classes are ages ago

If anyone is interested:

Since the solution is sin(pi*0.5*180/pi), which us equal to sin(x*90), just multiply any value x by 90 placed into the sin function to get the rad value...

It is nice to use instead of easing (e.g. a fade or motion) with a plain lerp function, since you can predetermine the exact time duration of the fading.

Just use

Cheers
B
8
S
3
Posts: 197
Reputation: 1,207

» Fri Feb 13, 2015 9:16 pm

Thank you @MultipleChoice for the math explanation which is invaluable.
B
127
S
54
G
24
Posts: 795
Reputation: 24,148

» Fri Mar 13, 2015 1:18 pm

> @alextro

Feel free to check out, what I used this for:

viewtopic.php?f=180&t=126638

@Kyatric Thanks once agin
B
8
S
3
Posts: 197
Reputation: 1,207

» Fri Mar 13, 2015 7:24 pm

Great math implementation both graphical & audio output. Thumbs up for interactive UI!
B
127
S
54
G
24
Posts: 795
Reputation: 24,148