2017 © Pedro Peláez
 

library decasteljau

A stupid way of using De Casteljau's algorithm to calculate control points of a segment in a cubic bezier curve.

image

nessworthy/decasteljau

A stupid way of using De Casteljau's algorithm to calculate control points of a segment in a cubic bezier curve.

  • Wednesday, July 18, 2018
  • by Sean
  • Repository
  • 1 Watchers
  • 0 Stars
  • 1 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Nessworthy / decasteljau

A stupid way of using De Casteljau's algorithm to calculate control points of a segment in a cubic bezier curve in PHP., (*1)

I used this a fair amount when trying to work out segments for SVG paths., (*2)

Requirements

  • PHP 7

Installation

composer require nessworthy/decasteljau, (*3)

Usage

The algorithm requires 6 pieces of information - the original 4 control points of your bezier curve, where you want to cut your segment, and how long you want your segment to be., (*4)

Example:, (*5)

<?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();

License

WTFPL - See LICENSE.md, (*6)

The Versions

18/07 2018

dev-master

9999999-dev

A stupid way of using De Casteljau's algorithm to calculate control points of a segment in a cubic bezier curve.

  Sources   Download

WTFPL

The Development Requires

by Sean Nessworthy

18/07 2018

1.0.0

1.0.0.0

A stupid way of using De Casteljau's algorithm to calculate control points of a segment in a cubic bezier curve.

  Sources   Download

WTFPL

The Development Requires

by Sean Nessworthy