Creates a Bézier curve by its control points. Implemented with de Casteljau method.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib
README.md
beziercurve.gemspec

README.md

Bézier Ruby Gem

A Ruby gem for creating and analyzing Bézier curves. Allows you to create a Bézier curve by its control points, get specific point on that curve or iterate the curve points by an Enumerator. Inspired by A Primer on Bézier Curves.

History

0.7 - implemented the De Casteljau algorithm

0.8 - defined minimum Ruby version (2.0.0)

Installation

> gem install beziercurve

Sample

> require 'beziercurve'
> bez = Bezier::Curve.new(Bezier::ControlPoint.new(40, 250), Bezier::ControlPoint.new(50, 150), Bezier::ControlPoint.new(90, 220))
> puts bez.point_on_curve(0.2).x;
45.2
> puts bez.point_on_curve(0.2).y;
216.8

or a nicer way:

> bez = Bezier::Curve.new([40, 250], [50, 150], [90, 220])
> puts bez.point_on_curve(0.2).x;
45.2
> puts bez.point_on_curve(0.2).y;
216.8