Class: Hermite

Phaser. Hermite

new Hermite(p1x, p1y, p2x, p2y, v1x, v1y, v2x, v2y [, accuracy])

A data representation of a Hermite Curve (see http://en.wikipedia.org/wiki/Cubic_Hermite_spline)

A Hermite curve has a start and end point and tangent vectors for both of them. The curve will always pass through the two control points and the shape of it is controlled by the length and direction of the tangent vectors. At the control points the curve will be facing exactly in the vector direction.

As these curves change speed (speed = distance between points separated by an equal change in 't' value - see Hermite.getPoint) this class attempts to reduce the variation by pre-calculating the accuracy number of points on the curve. The straight-line distances to these points are stored in the private 'points' array, and this information is used by Hermite.findT() to convert a pixel distance along the curve into a 'time' value.

Higher accuracy values will result in more even movement, but require more memory for the points list. 5 works, but 10 seems to be an ideal value for the length of curves found in most games on a desktop screen. If you use very long curves (more than 400 pixels) you may need to increase this value further.

Parameters:
Name Type Argument Default Description
p1x number

The x coordinate of the start of the curve.

p1y number

The y coordinate of the start of the curve.

p2x number

The x coordinate of the end of the curve.

p2y number

The y coordinate of the end of the curve.

v1x number

The x component of the tangent vector for the start of the curve.

v1y number

The y component of the tangent vector for the start of the curve.

v2x number

The x component of the tangent vector for the end of the curve.

v2y number

The y component of the tangent vector for the end of the curve.

accuracy number <optional>
10

The amount of points to pre-calculate on the curve.

Source:
src/geom/Hermite.js line 39

Members

accuracy : number

The amount of points to pre-calculate on the curve.

Type:
  • number
Source:
src/geom/Hermite.js line 396

p1x : number

The x coordinate of the start of the curve. Setting this value will recalculate the curve.

Type:
  • number
Source:
src/geom/Hermite.js line 420

p1y : number

The y coordinate of the start of the curve. Setting this value will recalculate the curve.

Type:
  • number
Source:
src/geom/Hermite.js line 444

p2x : number

The x coordinate of the end of the curve. Setting this value will recalculate the curve.

Type:
  • number
Source:
src/geom/Hermite.js line 468

p2y : number

The y coordinate of the end of the curve. Setting this value will recalculate the curve.

Type:
  • number
Source:
src/geom/Hermite.js line 492

v1x : number

The x component of the tangent vector for the start of the curve. Setting this value will recalculate the curve.

Type:
  • number
Source:
src/geom/Hermite.js line 516

v1y : number

The y component of the tangent vector for the start of the curve. Setting this value will recalculate the curve.

Type:
  • number
Source:
src/geom/Hermite.js line 540

v2x : number

The x component of the tangent vector for the end of the curve. Setting this value will recalculate the curve.

Type:
  • number
Source:
src/geom/Hermite.js line 564

v2y : number

The y component of the tangent vector for the end of the curve. Setting this value will recalculate the curve.

Type:
  • number
Source:
src/geom/Hermite.js line 588

Methods

calculateEvenPoints()

Calculate a number of points along the curve, based on Hermite.accuracy, and stores them in the private _points array.

Source:
src/geom/Hermite.js line 146
Returns:

The total length of the curve approximated as straight line distances between the points.

Type
number

findT(distance)

Convert a distance along this curve into a time value which will be between 0 and 1.

For example if this curve has a length of 100 pixels then findT(50) would return 0.5.

Parameters:
Name Type Description
distance integer

The distance into the curve in pixels. Should be a positive integer.

Source:
src/geom/Hermite.js line 173
Returns:

The time (t) value, a float between 0 and 1.

Type
number

getAngle( [t])

Calculate and return the angle, in radians, of the curves tangent based on time.

Parameters:
Name Type Argument Default Description
t number <optional>
0

The t (time) value at which to find the angle. Must be between 0 and 1.

Source:
src/geom/Hermite.js line 336
Returns:

The angle of the line at the specified t time value along the curve. The value is in radians.

Type
number

getAngleWithDistance( [distance])

Calculate and return the angle, in radians, of the curves tangent at the given pixel distance along the curves length.

Parameters:
Name Type Argument Default Description
distance number <optional>
0

The distance along the curve to get the angle from, in pixels.

Source:
src/geom/Hermite.js line 354
Returns:

The angle of the line at the specified distance along the curve. The value is in radians.

Type
number

getEntryTangent(point)

Get the angle of the curves entry point.

Parameters:
Name Type Description
point Phaser.Point | Object

The Phaser.Point object, or an Object with public x and y properties, in which the tangent vector values will be stored.

Source:
src/geom/Hermite.js line 376
Returns:

A Point object containing the tangent vector of this Hermite curve.

Type
Phaser.Point

getPoint( [t] [, point])

Get a point on the curve using the t (time) value, which must be between 0 and 1.

Parameters:
Name Type Argument Default Description
t number <optional>
0

The time value along the curve from which to extract a point. This is a value between 0 and 1, where 0 represents the start of the curve and 1 the end.

point Phaser.Point | Object <optional>

An optional Phaser.Point, or Object containing public x and y properties. If given the resulting values will be stored in the Objects x and y properties. If omitted a new Phaser.Point object is created.

Source:
src/geom/Hermite.js line 276
Returns:

An Object with the x, y coordinate of the curve at the specified t value set in its x and y properties.

Type
Phaser.Point

getPointWithDistance( [distance] [, point])

Get a point on the curve using the distance, in pixels, along the curve.

Parameters:
Name Type Argument Default Description
distance integer <optional>
0

The distance along the curve to get the point from, given in pixels.

point Phaser.Point | Object <optional>

An optional Phaser.Point, or Object containing public x and y properties. If given the resulting values will be stored in the Objects x and y properties. If omitted a new Phaser.Point object is created.

Source:
src/geom/Hermite.js line 309
Returns:

The point on the line at the specified 'distance' along the curve.

Type
Phaser.Point

getX( [t])

Get the X component of a point on the curve based on the t (time) value, which must be between 0 and 1.

Parameters:
Name Type Argument Default Description
t number <optional>
0

The time value along the curve from which to extract a point. This is a value between 0 and 1, where 0 represents the start of the curve and 1 the end.

Source:
src/geom/Hermite.js line 210
Returns:

The X component of a point on the curve based on the t (time) value.

Type
number

getY( [t])

Get the Y component of a point on the curve based on the t (time) value, which must be between 0 and 1.

Parameters:
Name Type Argument Default Description
t number <optional>
0

The time value along the curve from which to extract a point. This is a value between 0 and 1, where 0 represents the start of the curve and 1 the end.

Source:
src/geom/Hermite.js line 243
Returns:

The Y component of a point on the curve based on the t (time) value.

Type
number

recalculate()

Performs the curve calculations.

This is called automatically if you change any of the curves public properties, such as Hermite.p1x or Hermite.v2y.

If you adjust any of the internal private values, then call this to update the points.

Source:
src/geom/Hermite.js line 123
Returns:

This object.

Type
Phaser.Hermite

phaser-ce@2.9.2 is on GitHub and NPM

Documentation generated by JSDoc 3.5.4 on 2017-11-09 using Tomorrow.