Skip to main content

BezierCurve

BezierCurve

Cubic Bezier Curve class.

Consists of a start point, an end point, 2 control points, and the bounding box for the curve.

Link to an interactive cubic bezier curve with formulas: https://www.desmos.com/calculator/rptlhv5rx8.


Constructor

public BezierCurve

new BezierCurve(p1, p2, c1, c2)

Initializes bezier curve with the given start point, end point, and intermediate points. If no point(s) are given, then it will be initialized with a blank Vector. Bounding Box holds meaningless values by default.

Parameters

  •  p1: Vector – Initializes start point with given coordinates.

  •  p2: Vector – Initializes end point with given coordinates.

  •  c1: Vector – Initializes first control point with given coordinates.

  •  c2: Vector – Initializes second control point with given coordinates.


Properties

No publicly accessible properties on BezierCurve

private p1: Vector

The x, y coordinates of the start point.

private p2: Vector

The x, y coordinates of the end point.

private c1: Vector

The x, y coordinates of the first control point.

private c2: Vector

The x, y coordinates of the second control point.

private boundingBox: Transform

The Bounding Box that encases the entire curve.

private dirty: false | true

Whether the curve's data has been updated.


Methods

private getT

getT(a, b, c, mod, end) => number

Calculates t by using the quadratic formula with the given a, b, and c.

Parameters

  •  a: number – The a value in the quadratic formula.

  •  b: number – The b value in the quadratic formula.

  •  c: number – The c value in the quadratic formula.

  •  mod: 1 | -1 – The +/- in the quadratic formula.

  •  end: number – Returns end if result is undefined.

Returns

  •   number – The value of t, where t represents how far along the bezier curve the given point is.

private updateBoundingBox

updateBoundingBox() => void

Calculates the position and size of the bounding box, based on p1, p2, c1, and c2.

public setP1

setP1(v) => void

Changes start point (P1), for Bezier curve.

Parameters

  •  v: Vector – The x, y coordinates to set the point to.

public setP2

setP2(v) => void

Changes end point (P2) for Bezier curve.

Parameters

  •  v: Vector – The x, y coordinates to set the point to.

public setC1

setC1(v) => void

Changes first control point (C1) for Bezier curve.

Parameters

  •  v: Vector – The x, y coordinates to set the point to.

public setC2

setC2(v) => void

Changes second control point (C2) for Bezier curve.

Parameters

  •  v: Vector – The x, y coordinates to set the point to.

public getP1

getP1() => Vector

Returns start point of curve (p1).

Returns

  •   Vector – The x, y coordinates of the start point.

public getP2

getP2() => Vector

Returns end point of curve (p2).

Returns

  •   Vector – The x, y coordinates of the end point.

public getC1

getC1() => Vector

Returns first control point (C1) for Bezier curve.

Returns

  •   Vector – The x, y coordinates of the first control point.

public getC2

getC2() => Vector

Returns second control point (C2) for Bezier curve.

Returns

  •   Vector – The x, y coordinates of the second control point.

public getX

getX(t) => number

Calculates x coordinate of t.

Parameters

  •  t: number – How far along the bezier curve the given point is.

Returns

  •   number – The x coordinate of t.

public getY

getY(t) => number

Calculates y coordinate of t.

Parameters

  •  t: number – How far along the bezier curve the given point is.

Returns

  •   number – The y coordinate of t.

public getPos

getPos(t) => Vector

Calculates x and y coordinates of t.

Parameters

  •  t: number – How far along the bezier curve the given point is.

Returns

  •   Vector – The x and y coordinates of t.

public getDX

getDX(t) => number

Calculates the 1st derivative of x coord of t.

Parameters

  •  t: number – How far along the bezier curve the given point is.

Returns

  •   number – The 1st derivative of x coord of t.

public getDY

getDY(t) => number

Calculates the 1st derivative of y coord of t.

Parameters

  •  t: number – How far along the bezier curve the given point is.

Returns

  •   number – The 1st derivative of y coord of t.

public getDerivative

getDerivative(t) => Vector

Calculates the 1st derivatives of x and y coordinates of t.

Parameters

  •  t: number – How far along the bezier curve the given point is.

Returns

  •   Vector – The 1st derivatives of x and y coordinates of t.

public getDDX

getDDX(t) => number

Calculates the 2nd derivative of x coordinate of t.

Parameters

  •  t: number – How far along the bezier curve the given point is.

Returns

  •   number – The 2nd derivative of x coordinate of t.

public getDDY

getDDY(t) => number

Calculates the 2nd derivative of y coordinate of t.

Parameters

  •  t: number – How far along the bezier curve the given point is.

Returns

  •   number – The 2nd derivative of y coordinate of t.

public get2ndDerivative

get2ndDerivative(t) => Vector

Calculates the 2nd derivatives of x and y coordinates of t.

Parameters

  •  t: number – How far along the bezier curve the given point is.

Returns

  •   Vector – The 2nd derivative of x and y coordinates of t.

public getBoundingBox

getBoundingBox() => Transform

Bounding box accessor updates the bounding box and returns it.

Returns

  •   Transform – A Transform that contains the bounding box of the curve.

Static Methods

No static methods for BezierCurve