• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

Bezier.pmH A D19-Oct-20005.7 KiB22169

ChangesH A D18-Oct-2000597 2017

MANIFESTH A D18-Oct-200054 76

Makefile.PLH A D18-Oct-2000290 1410

READMEH A D19-Oct-20002.8 KiB8862

test.plH A D18-Oct-2000844 4731

README

1NAME
2    Math::Bezier - solution of Bezier Curves
3
4SYNOPSIS
5        use Math::Bezier;
6
7        # create curve passing list of (x, y) control points
8        my $bezier = Math::Bezier->new($x1, $y1, $x2, $y2, ..., $xn, $yn);
9
10        # or pass reference to list of control points
11        my $bezier = Math::Bezier->new([ $x1, $y1, $x2, $y2, ..., $xn, $yn]);
12
13        # determine (x, y) at point along curve, range 0 -> 1
14        my ($x, $y) = $bezier->point(0.5);
15
16        # returns list ref in scalar context
17        my $xy = $bezier->point(0.5);
18
19        # return list of 20 (x, y) points along curve
20        my @curve = $bezier->curve(20);
21
22        # returns list ref in scalar context
23        my $curve = $bezier->curve(20);
24
25DESCRIPTION
26    This module implements the algorithm for the solution of Bezier
27    curves as presented by Robert D. Miller in Graphics Gems V,
28    "Quick and Simple Bezier Curve Drawing".
29
30    A new Bezier curve is created using the new() constructor,
31    passing a list of (x, y) control points.
32
33        use Math::Bezier;
34
35        my @control = ( 0, 0, 10, 20, 30, -20, 40, 0 );
36        my $bezier  = Math::Bezier->new(@control);
37
38    Alternately, a reference to a list of control points may be
39    passed.
40
41        my $bezier  = Math::Bezier->new(\@control);
42
43    The point($theta) method can then be called on the object,
44    passing a value in the range 0 to 1 which represents the
45    distance along the curve. When called in list context, the
46    method returns the x and y coordinates of that point on the
47    Bezier curve.
48
49        my ($x, $y) = $bezier->point(0.5);
50        print "x: $x  y: $y\n
51
52    When called in scalar context, it returns a reference to a list
53    containing the x and y coordinates.
54
55        my $point = $bezier->point(0.5);
56        print "x: $point->[0]  y: $point->[1]\n";
57
58    The curve($n) method can be used to return a set of points
59    sampled along the length of the curve (i.e. in the range 0 <=
60    $theta <= 1). The parameter indicates the number of sample
61    points required, defaulting to 20 if undefined. The method
62    returns a list of ($x1, $y1, $x2, $y2, ..., $xn, $yn) points
63    when called in list context, or a reference to such an array
64    when called in scalar context.
65
66        my @points = $bezier->curve(10);
67
68        while (@points) {
69            my ($x, $y) = splice(@points, 0, 2);
70            print "x: $x  y: $y\n";
71        }
72
73        my $points = $bezier->curve(10);
74
75        while (@$points) {
76            my ($x, $y) = splice(@$points, 0, 2);
77            print "x: $x  y: $y\n";
78        }
79
80AUTHOR
81    Andy Wardley <abw@kfs.org>
82
83SEE ALSO
84    Graphics Gems 5, edited by Alan W. Paeth, Academic Press, 1995,
85    ISBN 0-12-543455-3. Section IV.8, 'Quick and Simple Bezier Curve
86    Drawing' by Robert D. Miller, pages 206-209.
87
88