Find cubic equation using known points

469 Views Asked by At

I'm writing a javascript game, and are working on some interpolation functions, but I don't have enough mathematical knowledge to work out this problem.

I want to use a cubic function for interpolation with this formula:

y=ax^3 + bx + c

I want to find a using two points [x1,y1] [x2,y2]

b and c are known values.

  • b is the 'slope' of the equation, and determines how 'curved' the returned results are (sorry about the bad explanation), and is set by the program
  • c is equal to y2

Is it possible to solve for a, using only these two points?

My ultimate goal is to interpolate (or map) any value x, that is between x1 and x2, to a value between y1 and y2, in a non-linear way, determined by this equation.

Let me know if I need to explain some things better.

Edit: Example of how it would work:

Points are defined as [0,0] [100,1000]

Given an x-value 50, a linear interpolation would return 500.

A non-linear interpolation (possibly cubic) would, depending on the slope, return a value higher or lower than 500.

1

There are 1 best solutions below

1
On BEST ANSWER

You have two equations in one unknown, so will usually not have a solution. From the first point alone, you can write $a=\frac{y1-bx1-c}{x1^3}$ The second point gives you a similar equation. If the two $a$ values agree, all is well. If not, which do you choose? Only one of your points will be on the curve.