Interpolation from A to C passing by B

  • I'm trying to set temperatures for every day and I would like to make a sine that helps me add or subtract temperature from every day with a given max and min temperatures. It doesn't need to be an accurate representation of a real-world scenario it works for me if it's mirrored and simple.

    Something like this:

    How can I make a formula to create that sine?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Temp =cosp(low, high, month*2/12)

    Should do it if month is 1-12

  • Thanks for answering Rojo I ended up with this for calculating every day's temperature:

    cosp(-12,28,(DayCount%(365+leapyear))*1.8/(365+leapyear))

    I ended up with 1.8 from just testing trying to get the temperatures I wanted in the right months.

    As it is it could work but I'm wondering how could I make it so higher temperatures have more "priority"?

    I don't know the correct term, make lower temperatures last less than the higher temperatures.

    Thanks in advance.

  • Well, cosp() is just a sine wave under the hood which is hard to adjust like that. It's probably too much math than what it's worth to find the polynomial that fits that curve, and while utilizing multiple bezier curves could work too it would still require some math solving.

    You could do a more visual method. I loaded your graph image as a sprite, and put the origin to the top left axis. Then turning on a 16x16 grid in the editor i added a 16x16 square sprite with the origin at the bottom left. I then placed copies one by one left to right over your graph image. The final step was to turn off the grid and resize the squares so the bottom left is on the curve on the image. Actually it worked out great since you seemed to use a 16x16 grid. An viola, we have manually defined the curve.

    dropbox.com/s/28qjc71ywa1g00p/custom_curve.capx

    There are probably simplifications of this.

  • Wow, this is great! also easily customizable I played around with it and made some modifications to fit my project better, first I made 12 bars instead of 15 for convenient storage in the array where I have all the month's information so I can associate every bar with a month and just save the data.height with their corresponding month to use the formula. It makes the curve less accurate but It's not a big deal.

    But since I was fascinated by the graph I played around while trying to understand the maths ended up adding tracking for the days displaying all the information for each day as the dot moves at increments of graphwidth/365 days.

    https://www.dropbox.com/s/9606sl492rrtv5j/custom_curve_mod.capx?dl=0

    The dot moves to 365 positions representing the days of the year, I don't know why but there's sometimes a weird 0,01 window of error on the temperature value from using the keyboard or the play bottom vs using the mouse.

    Anyway, thanks Rojo awesome tricks Learnt a lot!

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