nessworthy / decasteljau
一种使用 De Casteljau 算法来计算三次贝塞尔曲线中段控制点的愚蠢方法。
1.0.0
2018-07-18 09:25 UTC
Requires (Dev)
- phpunit/phpunit: ^7.2
This package is auto-updated.
Last update: 2024-09-18 06:14:22 UTC
README
使用De Casteljau 算法在 PHP 中计算三次贝塞尔曲线中段控制点的愚蠢方法。
当尝试确定 SVG 路径的段时,我相当多地使用了这种方法。
要求
- PHP 7
安装
composer require nessworthy/decasteljau
使用
该算法需要6条信息 - 您贝塞尔曲线的原始4个控制点、您想要切割的段的位置以及您想要的段的长度。
示例
<?php use Nessworthy\DeCasteljau\CubicBezierCurve; use Nessworthy\DeCasteljau\Point; $curve = new CubicBezierCurve( new Point(0, 0), // Your start point. new Point(75, 0), // The first curve point. new Point(150, 75), // The second curve point. new Point(150, 150) // Your finishing point. ); // Calculate control points for the third quarter of the original curve. $curveSegment = $curve->getSegment(0.5, 0.75); // Instance of CubicBezierCurve // Useful for calculating SVG bezier paths! echo 'M' . $curveSegment->getControlPoint1()->x() . ' ' . $curveSegment->getControlPoint1()->y(); echo ' C' . $curveSegment->getControlPoint2()->x() . ' ' . $curveSegment->getControlPoint2()->y(); echo ', ' . $curveSegment->getControlPoint3()->x() . ' ' . $curveSegment->getControlPoint3()->y(); echo ', ' . $curveSegment->getControlPoint4()->x() . ' ' . $curveSegment->getControlPoint4()->y();
许可证
WTFPL - 请参阅 LICENSE.md