Find a graph

BlitzMax Forums/BlitzMax Programming/Find a graph

Pineapple(Posted 2010) [#1]
I need to be able to find a point on a curved graph (a vertically flipped parabola) with three parameters: width of the curve, height of the curve, and where along its length the maximum height is attained.

What kind of formula would yield this result?


Midimaster(Posted 2010) [#2]
what is the formula of the curved graph?


Warpy(Posted 2010) [#3]
' y=a*x^2 + b*x + c ' is the formula of a parabola - it's just a quadratic equation. Working out what a,b and c should be depends on where your parabola is coming from. I can write up some code if you describe your problem a bit more.


Pineapple(Posted 2010) [#4]
Here's a bit of an illustration:

I don't think I can use a typical parabola because I'd have to find the exact exponent that gives me the width I need, and then that still doesn't cover the shifting of the vertex. I'm expecting to be doing something with a bezier.


Warpy(Posted 2010) [#5]
A catmull-rom spline might be more appropriate (there's some code in the code archives)


Pineapple(Posted 2010) [#6]
That looks like it will fit my needs well. I would, however, hugely appreciate a summary on how it works mathematically.


Warpy(Posted 2010) [#7]
um, well, first of all I'll explicitly link to my example in the code archives now I'm on my PC and not my phone. There's a brief explanation of the algorithm at the top of that code.

As for the mathematics, there isn't a huge amount to how these are derived. They're cubic curves, which means they're defined by a polynomial q(x) with degree 3 (there's a t^3 term in the formula).
Any section of the spline is defined by four control points - P0, P1, P2, and P3. The constraints are that:
- q(0) = P1, q(1) = P2 ; (the curve begins at P1 and ends at P2)
- the tangent (gradient of the curve) at P1 is parallel to the line P0-P2.
- the tangent at P2 is parallel to the line P1-P3.

From these constraints you can derive the formula for the catmull-rom spline.