pfaciana/bspline

PHP 中简单快速的等距节点 B-Spline 曲线实现。

1.0.0 2021-07-11 23:41 UTC

This package is auto-updated.

Last update: 2024-09-12 06:45:13 UTC


README

PHP 中简单快速的等距节点 B-Spline 曲线实现。通常,B-Spline 的基函数通过 De Boor 算法递归定义。但这个库包含了预计算的等距节点 B-Spline 基函数。因此,这个库运行非常快。

使用方法

$spline = new BSpline($points);
$spline->calcAt($t, $degree);
// or
$spline->run($degree);
  • points : 点的数组。可以是任何维度的向量数组。
  • degree : B-Spline 曲线的度数。degree 应该是 2, 3, 4 或 5。
  • t : B-Spline 的参数。t 的取值范围是 [0,1]。如果 t = 0,则返回 points 的第一个点。如果 t = 1,则返回 points 的最后一个点。

示例

$points = [[1,2],[2,3],[3,4]];
$spline = new BSpline($points);
for($t = 0; $t <= 1; $t += 0.01) {
    [$x, $y] = $spline->calcAt($t, 3);
}
// or
$sPoints = $spline->run(3);

演示在此处可用 这里

注意:这是 https://github.com/Tagussan/BSpline 的 PHP 版本。