SuperCollider CLASSES (extension)

BezierSpline

A Bézier spline is a series of Bézier curves joined end to end where the last point of one curve coincides with the starting point of the next curve.
Source: /home/egor/.local/share/SuperCollider/downloaded-quarks/splines/Spline.sc
Inherits from: LinearSpline : Object

Description

The Bézier curves lie between each point on the spline and have an array of 0 or more control points that express the curvature.

Like other spline classes, the points may be of 2 or more more dimensions. Control points should be of the same dimensional order as the points. The BezierSplineGui can only edit in 2D.

The number of control points determines the order of that segment:

(
b = BezierSpline(
    [ 0, 0 ],
        [  ],
    [ 1, 1 ],
        [ [ 1.56875, 0.3125 ] ],
    [ 2, 2 ],
        [ [ 2.23125, 0.54166666666667 ], [ 2.78125, 0.6875 ] ],
    [ 3, 3 ],
        [ [ 3.0375, 4.6875 ], [ 3.475, 1.3958333333333 ], [ 3.4875, 5.125 ] ],
    [ 4, 4 ],
        [ [ 4.2875, 1.875 ], [ 4.76875, 1.0208333333333 ], [ 4.38125, 4.3333333333333 ], [ 4.69375, 5.5416666666667 ] ],
    [ 5, 5 ],
    false);

b.gui(nil,1000@300);
)

Methods that return a point will return an array [x,y], not a Point object as that class is limited to 2 dimensions. Methods that take a point as setter may be either an array or a Point object that will be converted to a point array.

The gui allows fairly intuitive display and editing of points and control points.

Class Methods

*new ( ... things)

Points alternate with arrays of controlPoints. If no args are supplied then a simple linear spline (2 points, no control points) is created.

Arguments:

... things
BezierSpline(
    point,
      controlPoints,
    point2,
      controlPoints2,
    ...
    pointN,
      controlPointsN,

    isClosed
)

isClosed (boolean): if the spline loops back to the first point

Example:

 BezierSpline(
        0@0,
            [0.2@0.4],
        1@1,
            [],
        false
 );

Returns:

a BezierSpline

*fromPoints (points, controlPoints, isClosed: false)

An alternate constructor

Arguments:

points

The points for each segment.

controlPoints

Optional, defaulting to no controlPoints. An array of controlPoints arrays, one controlPoint array for each segment. It is of size one less than the number of points, as each controlPoint array is inbetween each point. controlPoint arrays may have 0 or more controlPoints. controlPoints should be of the same dimensional order as the points.

isClosed

if the spline loops back to the first point

Returns:

a BezierSpline

Inherited class methods

Instance Methods

-interpolate (divisions: 128)

Interpolate points along the spline path. Note they are not evenly spaced along the whole path, but interpolate per segment. For a more common usage see bilinearInterpolate

Arguments:

divisions

number of divisions per segment

Returns:

returns an array of points of size: (divisions * num segments)

-createPoint (p, i)

create and insert a new point p at index i. It will also create and insert a corresponding controlPoint array, which will be initially empty (linear).

Arguments:

p

the point as either an array or a Point object

i

the index to insert it at

-createControlPoint (p, pointi, cpi)

create a new controlPoint for a segment

Arguments:

p

the controlPoint as an array or a Point object

pointi

the segment number to insert it at

cpi

the controlPoint index to insert it at

Returns:

[pointi, last index of controlPoints] this is intended for the gui class which usually is what calls createControlPoint

-controlPoints

-controlPoints = value

set the controlPoints, which is an array of arrays of control points.

-deletePoint (i)

remove a point and its corresponding controlPoints

Arguments:

i

index of point to remove

-deleteControlPoint (pointi, i)

delete a specific control point from a segment's control point list

Arguments:

pointi

segment index

i

control point index

-isLinear

answers if the BezierSpline is only a single segment with no control points and thus a simple linear function

Returns:

boolean

-++ (thou)

concatenate another BezierSpline

Arguments:

thou

the other spline

Returns:

a new BezierSpline

-guiClass

specifies the ObjectGui subclass which builds the GUI for editing the spline

Returns:

ObjectGui subclass

-linear (t, p1, p2, cps)

used internally to interpolate between 2 points when there are no control points for the segment

Arguments:

t

0..1 position between p1 and p2

p1

point 1

p2

point 2

cps

control points, in this case not used since its a linear interpolation

Returns:

a point

-quadratic (t, p1, p2, cps)

used internally to quadratically interpolate between two points with 1 control point between them

Arguments:

t

0..1 position between p1 and p2

p1

point 1

p2

point 2

cps

control points, in this case an array of one controlPoint

Returns:

a point

-cubic (t, p1, p2, cps)

used internally to cubically interpolate between two points with 2 control points between them

-ntic (t, p1, p2, cps)

used internally to cubically interpolate between two points with 3 or more control points between them

Inherited instance methods

Undocumented instance methods

-add (p, cp)

-setControlPoint (i, di, val)

-sliceDimensions (dims)

-spliceDimensions (dims, other)

Examples

(
b = BezierSpline(
        0@0,
          [],
        1@1,
          [],
        false
    );

b.gui
)

Click a knot to select that segment. Double click to create a point after the selected segment. Control-double click to create a control point within the selected segment.

The Spline's compile string saves the current state:

b.asCompileString
(
b = BezierSpline(
        0@0,
          [0.2@0.4],
        1@1,
          [],
        false
    );

b.gui
)
(
b = BezierSpline(
        0@0,
          [ 0.2@0.4, 0.5@0.9  ],
        1@1,
          [],
        false
    );

b.gui(nil,1000@300);
)