Class: CubicBezierCurve

CubicBezierCurve(startPoint, endPoint, startControlPoint, endControlPoint)

new CubicBezierCurve(startPoint, endPoint, startControlPoint, endControlPoint)

The constructor.
Parameters:
Name Type Description
startPoint Vertex The Bézier curve's start point.
endPoint Vertex The Bézier curve's end point.
startControlPoint Vertex The Bézier curve's start control point.
endControlPoint Vertex The Bézier curve's end control point.
Source:

Methods

(static) fromArray(arr) → {CubicBezierCurve}

Convert a 4-element array of vertices to a cubic bézier curve.
Parameters:
Name Type Description
arr Array:.<Vertex:> [ startVertex, endVertex, startControlVertex, endControlVertex ]
Source:
Throws:
An exception if the passed array is malformed.
Returns:
Type
CubicBezierCurve

(static) fromJSON(jsonString) → {CubicBezierCurve}

Parse a Bézier curve from the given JSON string.
Parameters:
Name Type Description
jsonString string The JSON data to parse.
Source:
Throws:
An exception if the JSON string is malformed.
Returns:
Type
CubicBezierCurve

(static) fromObject(obj) → {CubicBezierCurve}

Try to convert the passed object to a CubicBezierCurve.
Parameters:
Name Type Description
obj object The object to convert.
Source:
Throws:
An exception if the passed object is malformed.
Returns:
Type
CubicBezierCurve

clone() → {CubicBezierCurve}

Clone this Bézier curve (deep clone).
Source:
Returns:
Type
CubicBezierCurve

clone(curve) → {boolean}

Check if this and the specified curve are equal.

All four points need to be equal for this, the Vertex.equals function is used.

Please note that this function is not type safe (comparison with any object will fail).
Parameters:
Name Type Description
curve CubicBezierCurve The curve to compare with.
Source:
Returns:
Type
boolean

convertU2t(u) → {number}

Convert a relative curve position u to the absolute curve position t.
Parameters:
Name Type Description
u number The relative position on the curve in [0,arcLength].
Source:
Returns:
Type
number

getEndControlPoint() → {Vertex}

Get the end control point of the curve.

This function just returns this.endControlPoint.
Source:
Returns:
this.endControlPoint
Type
Vertex

getEndControlPoint(id) → {Vertex}

Get one of the four curve points specified by the passt point ID.
Parameters:
Name Type Description
id number One of START_POINT, START_CONTROL_POINT, END_CONTROL_POINT or END_POINT.
Source:
Returns:
Type
Vertex

getEndPoint() → {Vertex}

Get the end point of the curve.

This function just returns this.endPoint.
Source:
Returns:
this.endPoint
Type
Vertex

getLength() → {number}

Get the total curve length.

As not all Bézier curved have a closed formula to calculate their lengths, this implementation uses a segment buffer (with a length of 30 segments). So the returned length is taken from the arc segment buffer.

Note that if the curve points were changed and the segment buffer was not updated this function might return wrong (old) values.
Source:
Returns:
>= 0
Type
number

getPerpendicular(u) → {Vertex}

Get the curve perpendicular at a given relative position u in [0,arcLength] as a vector.

Note that the returned vector (end point) is not normalized.
Parameters:
Name Type Description
u number The relative position on the curve in [0,arcLength].
Source:
Returns:
Type
Vertex

getPerpendicularAt(u) → {Vertex}

Get the curve perpendicular at a given absolute position t in [0,1] as a vector.

Note that the returned vector (end point) is not normalized.
Parameters:
Name Type Description
u number The absolute position on the curve in [0,1].
Source:
Returns:
Type
Vertex

getPoint(u) → {Vertex}

Get the curve point at a given position u, where u is in [0,arcLength].

Parameters:
Name Type Description
u number The position on the curve in [0,arcLength] (0 means at start point, arcLength means at end point, other values address points in bertween).
Source:
See:
  • CubicBezierCurve.getPointAt
Returns:
Type
Vertex

getPointAt(t) → {Vertex}

Get the curve point at a given position t, where t is in [0,1].

Parameters:
Name Type Description
t number The position on the curve in [0,1] (0 means at start point, 1 means at end point, other values address points in bertween).
Source:
See:
  • Line.pointAt
Returns:
Type
Vertex

getStartControlPoint() → {Vertex}

Get the start control point of the curve.

This function just returns this.startControlPoint.
Source:
Returns:
this.startControlPoint
Type
Vertex

getStartPoint() → {Vertex}

Get the start point of the curve.

This function just returns this.startPoint.
Source:
Returns:
this.startPoint
Type
Vertex

getSubCurveAt(tStart, tEnd) → {CubicBezierCurve}

Get a sub curve at the given start end end offsets (values between 0.0 and 1.0). tStart >= tEnd is allowed, you will get a reversed sub curve then.
Parameters:
Name Type Description
tStart number – The start offset of the desired sub curve (must be in [0..1]).
tEnd number – The end offset if the desired cub curve (must be in [0..1]).
Source:
Returns:
The sub curve as a new curve.
Type
CubicBezierCurve

getTangent(t) → {Vertex}

Get the curve tangent vector at a given absolute curve position t in [0,1].

Note that the returned tangent vector (end point) is not normalized and relative to (0,0).
Parameters:
Name Type Description
t number The position on the curve in [0,1].
Source:
Returns:
Type
Vertex

getTangent(u) → {Vertex}

Get the curve tangent vector at a given relative position u in [0,arcLength].

Note that the returned tangent vector (end point) is not normalized.
Parameters:
Name Type Description
u number The position on the curve in [0,arcLength].
Source:
Returns:
Type
Vertex

isInstance(obj) → {boolean}

Quick check for class instance. Is there a better way?
Parameters:
Name Type Description
obj any Check if the passed object/value is an instance of CubicBezierCurve.
Source:
Returns:
Type
boolean

moveCurvePoint(pointID, moveAmount, moveControlPoint, updateArcLengths) → {void}

Move the given curve point (the start point, end point or one of the two control points).
Parameters:
Name Type Description
pointID number The numeric identicator of the point to move. Use one of the four eBezierPoint constants.
moveAmount XYCoords The amount to move the specified point by.
moveControlPoint boolean Move the control points along with their path point (if specified point is a path point).
updateArcLengths boolean Specifiy if the internal arc segment buffer should be updated.
Source:
Returns:
Type
void

reverse() → {CubicBezierCurve}

Reverse this curve, means swapping start- and end-point and swapping start-control- and end-control-point.
Source:
Returns:
this (for chaining).
Type
CubicBezierCurve

toJSON(prettyFormatopt) → {string}

Convert this curve to a JSON string.
Parameters:
Name Type Attributes Default Description
prettyFormat boolean <optional>
false If set to true the function will add line breaks.
Source:
Returns:
The JSON data.
Type
string

toSVGPathData() → {string}

Create an SVG path data representation of this bézier curve. Path data string format is:
'M x0 y1 C dx0 dy1 dx1 dy1 x1 x2'

or in other words
'M startoint.x startPoint.y C startControlPoint.x startControlPoint.y endControlPoint.x endControlPoint.y endPoint.x endPoint.y'
Source:
Returns:
The SVG path data string.
Type
string

translate(amount) → {CubicBezierCurve}

Translate the whole curve by the given {x,y} amount: moves all four points.
Parameters:
Name Type Description
amount Vertex The amount to translate this curve by.
Source:
Returns:
this (for chaining).
Type
CubicBezierCurve

updateArcLengths() → {void}

Uptate the internal arc segment buffer and their lengths.

All class functions update the buffer automatically; if any curve point is changed by other reasons you should call this function to keep actual values in the buffer.
Source:
Returns:
Type
void