将二维样条函数 f(t) 转换为 f(x) [英] Transform 2d spline function f(t) into f(x)

查看:21
本文介绍了将二维样条函数 f(t) 转换为 f(x)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一组特殊的三次样条,它的 2d 控制点总是会产生一条永远不会在 x 轴上相交的曲线.也就是说,曲线看起来像是一个简单的多项式函数,使得y=f(x).我想沿着样条有效地创建一个 y 坐标数组,这些坐标对应于运行样条线段长度的均匀分布的 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.

我想有效地找到沿样条线的 y 坐标,例如 x=0.0, x=0.1, x=0.2 等,或采用另一种方式,有效地将 fx,y(t) 样式函数转换为 f(x) 函数.

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.

我目前使用 4x4 常数矩阵和四个 2d 控制点来描述样条,使用 Hermite 或 Catmull-Rom 样条的矩阵常数,并将它们插入 t 的三次函数从 0 到 1.

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.

给定矩阵和控制点,在 x 轴上获得这些 y 值的最佳方法是什么?

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

我应该补充一点,足以绘制的近似值就足够了.

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

推荐答案

你的问题说你想要均匀的空间x坐标,近似解就可以了.所以我提出如下算法:

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

  • 决定你想要的网格点,例如每 0.1 x 个单位一个.
  • l = 0 和 r = 1 开始.
  • 计算 fx(l) 和 fx(>r) 并考虑由这些端点表示的间隔.
    • 如果区间足够小并且恰好包含一个网格点,则使用中心参数t=(l+r)/2作为此网格点的一个很好的近似值,并将其作为单元素列表返回.
    • 如果该区间内至少有一个网格点,则使用 (l+r)/2 作为分割点将其一分为二,并将结果连接起来两个计算中的列表.
    • 如果区间内没有网格点,则跳过计算的当前分支,返回一个空列表.
    • 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.

      这篇关于将二维样条函数 f(t) 转换为 f(x)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆