An Elliptical Curve derived from the Base Curve class.
See https://en.wikipedia.org/wiki/Elliptic_curve for more details.
new Ellipse([x], [y], [xRadius], [yRadius], [startAngle], [endAngle], [clockwise], [rotation])
name | type | arguments | Default | description |
---|---|---|---|---|
x | number | Phaser.Types.Curves.EllipseCurveConfig | <optional> | 0 |
The x coordinate of the ellipse, or an Ellipse Curve configuration object. |
y | number | <optional> | 0 |
The y coordinate of the ellipse. |
xRadius | number | <optional> | 0 |
The horizontal radius of ellipse. |
yRadius | number | <optional> | 0 |
The vertical radius of ellipse. |
startAngle | number | <optional> | 0 |
The start angle of the ellipse, in degrees. |
endAngle | number | <optional> | 360 |
The end angle of the ellipse, in degrees. |
clockwise | boolean | <optional> | false |
Whether the ellipse angles are given as clockwise ( |
rotation | number | <optional> | 0 |
The rotation of the ellipse, in degrees. |
For a curve on a Path, false
means the Path will ignore this curve.
The rotation of the ellipse, relative to the center, in degrees.
The quantity of arc length divisions within the curve.
An array of cached arc length values.
true
if the ellipse rotation is clockwise or false
if anti-clockwise.
The default number of divisions within the curve.
The end angle of the ellipse in degrees.
Does the data of this curve need updating?
The center point of the ellipse. Used for calculating rotation.
The rotation of the ellipse, relative to the center, in radians.
The start angle of the ellipse in degrees.
String based identifier for the type of curve.
The x coordinate of the center of the ellipse.
The horizontal radius of the ellipse.
The y coordinate of the center of the ellipse.
The vertical radius of the ellipse.
Draws this curve on the given Graphics object.
The curve is drawn using Graphics.strokePoints
so will be drawn at whatever the present Graphics stroke color is.
The Graphics object is not cleared before the draw, so the curve will appear on-top of anything else already rendered to it.
name | type | arguments | Default | description |
---|---|---|---|---|
graphics | Phaser.GameObjects.Graphics |
The Graphics instance onto which this curve will be drawn. |
||
pointsTotal | number | <optional> | 32 |
The resolution of the curve. The higher the value the smoother it will render, at the cost of rendering performance. |
The Graphics object to which the curve was drawn.
Returns a Rectangle where the position and dimensions match the bounds of this Curve.
You can control the accuracy of the bounds. The value given is used to work out how many points to plot across the curve. Higher values are more accurate at the cost of calculation speed.
name | type | arguments | Default | description |
---|---|---|---|---|
out | Phaser.Geom.Rectangle | <optional> |
The Rectangle to store the bounds in. If falsey a new object will be created. |
|
accuracy | number | <optional> | 16 |
The accuracy of the bounds calculations. |
A Rectangle object holding the bounds of this curve. If out
was given it will be this object.
Returns an array of points, spaced out X distance pixels apart. The smaller the distance, the larger the array will be.
name | type | description |
---|---|---|
distance | number |
The distance, in pixels, between each point along the curve. |
An Array of Point objects.
Get a point at the end of the curve.
name | type | arguments | description |
---|---|---|---|
out | Phaser.Math.Vector2 | <optional> |
Optional Vector object to store the result in. |
Vector2 containing the coordinates of the curves end point.
Get total curve arc length
The total length of the curve.
Get a list of cumulative segment lengths.
These lengths are
name | type | arguments | description |
---|---|---|---|
divisions | number | <optional> |
The number of divisions or segments. |
An array of cumulative lengths.
Get point at relative position in curve according to length.
name | type | arguments | description |
---|---|---|---|
t | number |
The position along the curve to return. Where 0 is the start and 1 is the end. |
|
out | Phaser.Math.Vector2 | <optional> |
A Vector2 object to store the result in. If not given will be created. |
The coordinates of the point on the curve. If an out
object was given this will be returned.
Get a point at a relative position on the curve, by arc length.
name | type | arguments | description |
---|---|---|---|
u | number |
The relative position, [0..1]. |
|
out | Phaser.Math.Vector2 | <optional> |
A point to store the result in. |
The point.
Get a sequence of evenly spaced points from the curve.
You can pass divisions
, stepRate
, or neither.
The number of divisions will be
divisions
, if divisions
> 0; orthis.getLength / stepRate
, if stepRate
> 0; orthis.defaultDivisions
1 + divisions
points will be returned.
name | type | arguments | description |
---|---|---|---|
divisions | number | <optional> |
The number of divisions to make. |
stepRate | number | <optional> |
The curve distance between points, implying |
out | array | Array.<Phaser.Math.Vector2> | <optional> |
An optional array to store the points in. |
An array of Points from the curve.
Get a random point from the curve.
name | type | arguments | description |
---|---|---|---|
out | Phaser.Math.Vector2 | <optional> |
A point object to store the result in. |
The point.
Get the resolution of the curve.
name | type | description |
---|---|---|
divisions | number |
Optional divisions value. |
The curve resolution.
Get a sequence of equally spaced points (by arc distance) from the curve.
1 + divisions
points will be returned.
name | type | arguments | Default | description |
---|---|---|---|---|
divisions | number | <optional> | this.defaultDivisions |
The number of divisions to make. |
stepRate | number | <optional> |
Step between points. Used to calculate the number of points to return when divisions is falsy. Ignored if divisions is positive. |
|
out | array | Array.<Phaser.Math.Vector2> | <optional> |
An optional array to store the points in. |
An array of points.
Gets the starting point on the curve.
name | type | arguments | description |
---|---|---|---|
out | Phaser.Math.Vector2 | <optional> |
A Vector2 object to store the result in. If not given will be created. |
The coordinates of the point on the curve. If an out
object was given this will be returned.
Given a distance in pixels, get a t to find p.
name | type | arguments | description |
---|---|---|---|
distance | number |
The distance, in pixels. |
|
divisions | number | <optional> |
Optional amount of divisions. |
The distance.
Get a unit vector tangent at a relative position on the curve. In case any sub curve does not implement its tangent derivation, 2 points a small delta apart will be used to find its gradient which seems to give a reasonable approximation
name | type | arguments | description |
---|---|---|---|
t | number |
The relative position on the curve, [0..1]. |
|
out | Phaser.Math.Vector2 | <optional> |
A vector to store the result in. |
Vector approximating the tangent line at the point t (delta +/- 0.0001)
Get a unit vector tangent at a relative position on the curve, by arc length.
name | type | arguments | description |
---|---|---|---|
u | number |
The relative position on the curve, [0..1]. |
|
out | Phaser.Math.Vector2 | <optional> |
A vector to store the result in. |
The tangent vector.
Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant.
name | type | arguments | description |
---|---|---|---|
u | number |
A float between 0 and 1. |
|
distance | number |
The distance, in pixels. |
|
divisions | number | <optional> |
Optional amount of divisions. |
The equidistant value.
Sets if this curve extends clockwise or anti-clockwise.
name | type | description |
---|---|---|
value | boolean |
The clockwise state of this curve. |
This curve object.
Sets the end angle of this curve.
name | type | description |
---|---|---|
value | number |
The end angle of this curve, in radians. |
This curve object.
Sets the height of this curve.
name | type | description |
---|---|---|
value | number |
The height of this curve. |
This curve object.
Sets the rotation of this curve.
name | type | description |
---|---|---|
value | number |
The rotation of this curve, in radians. |
This curve object.
Sets the start angle of this curve.
name | type | description |
---|---|---|
value | number |
The start angle of this curve, in radians. |
This curve object.
Sets the width of this curve.
name | type | description |
---|---|---|
value | number |
The width of this curve. |
This curve object.
Sets the horizontal radius of this curve.
name | type | description |
---|---|---|
value | number |
The horizontal radius of this curve. |
This curve object.
Sets the vertical radius of this curve.
name | type | description |
---|---|---|
value | number |
The vertical radius of this curve. |
This curve object.
JSON serialization of the curve.
The JSON object containing this curve data.
Calculate and cache the arc lengths.
Creates a curve from the provided Ellipse Curve Configuration object.
name | type | description |
---|---|---|
data | Phaser.Types.Curves.JSONEllipseCurve |
The JSON object containing this curve data. |
The ellipse curve constructed from the configuration object.