How do I calculate a classic sin(x) function

  • 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?

  • 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.)

  • 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!

  • 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

  • Thank you MultipleChoice for the math explanation which is invaluable.

  • alextro

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

    Kyatric Thanks once agin

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Great math implementation both graphical & audio output. Thumbs up for interactive UI!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)