Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transform 2d spline function f(t) into f(x)

So I've got a special case set of cubic splines, whose 2d control points will always result in a curve that will never cross itself in the x axis. That is, the curves look like they could be a simple polynomial function such that y=f(x). I want to efficiently create an array of y coordinates along the spline that correspond to evenly-spaced x coordinates running the length of the spline segment.

I want to efficiently find the y coordinates along the spline where, for instance, x=0.0, x=0.1, x=0.2, etc., or approached another way, effectively transform the fx,y(t) style function into an f(x) function.

I'm currently using a 4x4 constant matrix and four 2d control points to describe the spline, using matrix constants for either Hermite or Catmull-Rom splines, and plugging them into a cubic function of t going from 0 to 1.

Given the matrix and the control points, what's the best way to obtain these y values over the x axis?

EDIT: I should add that an approximation good enough to draw is sufficient.

like image 511
vercellop Avatar asked Jul 17 '12 07:07

vercellop


People also ask

How to use matlab spline function?

Description. s = spline( x , y , xq ) returns a vector of interpolated values s corresponding to the query points in xq . The values of s are determined by cubic spline interpolation of x and y . pp = spline( x , y ) returns a piecewise polynomial structure for use by ppval and the spline utility unmkpp .

What is cubic spline function?

A cubic spline is a piecewise cubic function that interpolates a set of data points and guarantees smoothness at the data points.

What is B spline interpolation?

Convolution of the signal with a rectangle function gives first order interpolated B-spline values. Second-order B-spline interpolation is convolution with a rectangle function twice. ; by iterative filtering with a rectangle function, higher-order interpolation is obtained.


2 Answers

Often people will use a root finding technique (like Newton's Method) if an numerical approximation is good enough.

like image 115
Jeff Gates Avatar answered Oct 14 '22 02:10

Jeff Gates


Well, you could solve your fx(t)=x for t. That would be a cubic equation; ugly but still possible to solve explicitely. If your spline is as you describe it, then two of the solutions will be conjugate complex, so the only remaining one is the one to take. Use that to compute y=fy(t). I doubt you can accompish anything easier if you want exact solutions.

You can use the general formula from Wikipedia to compute the solution of the cubic equation.

like image 29
MvG Avatar answered Oct 14 '22 02:10

MvG