How do I calculate a classic sin(x) function

Get help using Construct 2

Post » 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

Post » 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

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
270
S
98
G
70
Posts: 7,267
Reputation: 75,644

Post » 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

Post » 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

lerp (MinValue, MaxValue, sin(TimeEllapsed*90*1/FadeDuration_in_Sec))



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

Post » Fri Feb 13, 2015 9:16 pm

Thank you @MultipleChoice for the math explanation which is invaluable.
ImageImage
B
91
S
43
G
21
Posts: 739
Reputation: 20,448

Post » 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

Post » Fri Mar 13, 2015 7:24 pm

Great math implementation both graphical & audio output. Thumbs up for interactive UI!
ImageImage
B
91
S
43
G
21
Posts: 739
Reputation: 20,448


Return to How do I....?

Who is online

Users browsing this forum: bigezy80, imhotep22, Laurent, Yahoo [Bot] and 10 guests