I’m trying to use the .Net Chart object to interactively define a spline function that I use to map from one range of values to another. In other words, I have a 0-4095 range (x axis) that I want to convert to a 0-100 range (y axis) using a spline. I’ve successfully set up a chart that plots a spline through a group of points. The user can interactively move the points to get the desired function shape. Works great.
Now…once I have the spline like the user wants, how can I (using the spline function), find the corresponding y value for any x value?
I can’t seem to find a way to do that. I know that the chart object is doing the calculation somewhere since it’s plotting the spline…maybe they don’t provide access to that.
The alternative is to make the spline calculations myself…I don’t want to go there unless absolutely necessary.
Thanks.
Bryan
You need to find the value of “t” (tension parameter) that produces the desired value of x. if you are using the range of 0 to 1 the parameter “t” value will be somewhere near to 0.5. Once you know t you can calculate the corresponding value of y. Solve a cubic equation which will generate 3 values for “t” that will result in same value of x. Check the link below.
http://algorithmist.wordpress.com/2009/09/28/cardinal-splines-part-2/
Cardinal splines specify the tangents at interior points based on the vector from previous point to subsequent point. Each tangent is parallel to this vector and some multiple of its length. For example, the tangent direction at point P1 is parallel to the vector P2 – P0, or we could simply write something like T1 = s(P2 – P0) where s is a real number.
Check this part of code below where xtarget is the input value x.
Code:
The above method will give the approximate point P(t)y on the curve.