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

人盡茶涼 提交于 2019-11-27 06:51:48

问题


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.


回答1:


Your question states that you want evenly spaces x coordinates, and approximate solutions are all right. So I propose the following algorithm:

  • Decide on the grid points you want, e.g. one every 0.1 x units.
  • Start with l = 0 and r = 1.
  • Compute fx(l) and fx(r) and consider the interval denoted by these endpoints.
    • If the interval is sufficiently small and contains exactly one grid point, use the central parameter t=(l+r)/2 as a good approximation for this grid point, and return that as a one-element list.
    • If there is at least one grid point in that interval, split it in two using (l+r)/2 as the splitting point, and concatenate the resulting lists from both computations.
    • If there is no grid point in the interval, then skip the current branch of the computation, returning an empty list.

This will zoom in on the grid points, bisecting the parameter space in each step, and will come up with suitable parameters for all your grid points.




回答2:


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




回答3:


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.



来源:https://stackoverflow.com/questions/11518054/transform-2d-spline-function-ft-into-fx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!