Function generation by input $y$ and $x$ values

622 Views Asked by At

I wonder if there are such tools, that can output function formulas that match input conditions. Lets say I will make input like that:

$y=0, x=0$

$y=1, x=1$

$y=2, x=4$

and tool should generate for me function formula y=x^2. I am aware its is not possible to find out exact function, but it would be great to get some possibilities. I'm game developer and i need to code some behaviours in game mechanics, that aren't simply linear, sometimes I need for example arcus tangens, when i want my value to increase slower and slower for higher arguments. Problem is that I finished my school long time ago and simply I don't remember how does many functions looks like and such tool would be great to quickly find out what i need.

4

There are 4 best solutions below

0
On

One of my favorite curve-fitting resources is zunzun. They have many, many possible types of curves that can fit the data you give it.

1
On

You are looking for something like a polynomial fitting or regression analysis. Take a look at http://en.wikipedia.org/wiki/Polynomial_regression .

0
On

While it is possible to find e.g. a polynomial of degree $n-1$ that exactly passes through $n$ given points, this is probably not what you need: Such interpolating polynomials tend to oscillate in a nondesireable fashion. Since I assume that speed of calculation is an issue, I suggest to simply use linear interpolation between consecutive points - this may be much faster than a convoluted expression involving $\arctan$ and others. If you prefer a smoothe curve, try cubic spline interpolation - it's good enough to construct a roller coaster that doesn't get bumpy. Also it has the advantages that adjustment to one of the given points has no side-effects on points that are far away from it.

0
On

Simple "ramp" or "easing" functions that describe position as a function of time are common in games and other types of animation. Often, you want the speed of the object to vary, which means that the function graph won't be a straight line.

A couple of simple cases are described in this answer and in this answer.

You can usually get what you need just by using a simple low-degree polynomial (quadratic or cubic). If you tell us what kind of behaviour/properties you want, it should be easy to construct the function. It's best if you can provide a graph of the desired function.