new Triangle( [x1] [, y1] [, x2] [, y2] [, x3] [, y3])
Parameters:
| Name | Type | Argument | Default | Description |
|---|---|---|---|---|
x1 |
number |
<optional> |
0 |
|
y1 |
number |
<optional> |
0 |
|
x2 |
number |
<optional> |
0 |
|
y2 |
number |
<optional> |
0 |
|
x3 |
number |
<optional> |
0 |
|
y3 |
number |
<optional> |
0 |
|
- Since: 3.0.0
- Source: src/geom/triangle/Triangle.js (Line 15)
Members
-
bottom :number
-
Bottom most Y coordinate of the triangle. Setting it moves the triangle on the Y axis accordingly.
Type:
- number
- Since: 3.0.0
- Source: src/geom/triangle/Triangle.js (Line 401)
-
left :number
-
Left most X coordinate of the triangle. Setting it moves the triangle on the X axis accordingly.
Type:
- number
- Since: 3.0.0
- Source: src/geom/triangle/Triangle.js (Line 287)
-
right :number
-
Right most X coordinate of the triangle. Setting it moves the triangle on the X axis accordingly.
Type:
- number
- Since: 3.0.0
- Source: src/geom/triangle/Triangle.js (Line 325)
-
top :number
-
Top most Y coordinate of the triangle. Setting it moves the triangle on the Y axis accordingly.
Type:
- number
- Since: 3.0.0
- Source: src/geom/triangle/Triangle.js (Line 363)
-
<readonly> type :number
-
The geometry constant type of this object:
GEOM_CONST.TRIANGLE. Used for fast type comparisons.Type:
- number
- Since: 3.19.0
- Source: src/geom/triangle/Triangle.js (Line 46)
-
x1 :number
-
xcoordinate of the first point.Type:
- number
- Since: 3.0.0
- Default Value:
-
- 0
- Source: src/geom/triangle/Triangle.js (Line 57)
-
x2 :number
-
xcoordinate of the second point.Type:
- number
- Since: 3.0.0
- Default Value:
-
- 0
- Source: src/geom/triangle/Triangle.js (Line 77)
-
x3 :number
-
xcoordinate of the third point.Type:
- number
- Since: 3.0.0
- Default Value:
-
- 0
- Source: src/geom/triangle/Triangle.js (Line 97)
-
y1 :number
-
ycoordinate of the first point.Type:
- number
- Since: 3.0.0
- Default Value:
-
- 0
- Source: src/geom/triangle/Triangle.js (Line 67)
-
y2 :number
-
ycoordinate of the second point.Type:
- number
- Since: 3.0.0
- Default Value:
-
- 0
- Source: src/geom/triangle/Triangle.js (Line 87)
-
y3 :number
-
ycoordinate of the third point.Type:
- number
- Since: 3.0.0
- Default Value:
-
- 0
- Source: src/geom/triangle/Triangle.js (Line 107)
Methods
-
<static> Area(triangle)
-
Returns the area of a Triangle.
Parameters:
Name Type Description trianglePhaser.Geom.Triangle The Triangle to use.
- Since: 3.0.0
- Source: src/geom/triangle/Area.js (Line 9)
Returns:
The area of the Triangle, always non-negative.
- Type
- number
-
<static> BuildEquilateral(x, y, length)
-
Builds an equilateral triangle. In the equilateral triangle, all the sides are the same length (congruent) and all the angles are the same size (congruent). The x/y specifies the top-middle of the triangle (x1/y1) and length is the length of each side.
Parameters:
Name Type Description xnumber x coordinate of the top point of the triangle.
ynumber y coordinate of the top point of the triangle.
lengthnumber Length of each side of the triangle.
- Since: 3.0.0
- Source: src/geom/triangle/BuildEquilateral.js (Line 9)
Returns:
The Triangle object of the given size.
- Type
- Phaser.Geom.Triangle
-
<static> BuildFromPolygon(data [, holes] [, scaleX] [, scaleY] [, out])
-
Takes an array of vertex coordinates, and optionally an array of hole indices, then returns an array of Triangle instances, where the given vertices have been decomposed into a series of triangles.
Parameters:
Name Type Argument Default Description dataarray A flat array of vertex coordinates like [x0,y0, x1,y1, x2,y2, ...]
holesarray <optional>
null An array of hole indices if any (e.g. [5, 8] for a 12-vertex input would mean one hole with vertices 5–7 and another with 8–11).
scaleXnumber <optional>
1 Horizontal scale factor to multiply the resulting points by.
scaleYnumber <optional>
1 Vertical scale factor to multiply the resulting points by.
outarray | Array.<Phaser.Geom.Triangle> <optional>
An array to store the resulting Triangle instances in. If not provided, a new array is created.
- Since: 3.0.0
- Source: src/geom/triangle/BuildFromPolygon.js (Line 10)
Returns:
An array of Triangle instances, where each triangle is based on the decomposed vertices data.
- Type
- array | Array.<Phaser.Geom.Triangle>
-
<static> BuildRight(x, y, width, height)
-
Builds a right triangle, i.e. one which has a 90-degree angle and two acute angles.
Parameters:
Name Type Description xnumber The X coordinate of the right angle, which will also be the first X coordinate of the constructed Triangle.
ynumber The Y coordinate of the right angle, which will also be the first Y coordinate of the constructed Triangle.
widthnumber The length of the side which is to the left or to the right of the right angle.
heightnumber The length of the side which is above or below the right angle.
- Since: 3.0.0
- Source: src/geom/triangle/BuildRight.js (Line 13)
Returns:
The constructed right Triangle.
- Type
- Phaser.Geom.Triangle
-
<static> CenterOn(triangle, x, y [, centerFunc])
-
Positions the Triangle so that it is centered on the given coordinates.
Parameters:
Name Type Argument Description trianglePhaser.Geom.Triangle The triangle to be positioned.
xnumber The horizontal coordinate to center on.
ynumber The vertical coordinate to center on.
centerFuncCenterFunction <optional>
The function used to center the triangle. Defaults to Centroid centering.
- Since: 3.0.0
- Source: src/geom/triangle/CenterOn.js (Line 18)
Returns:
The Triangle that was centered.
- Type
- Phaser.Geom.Triangle
-
<static> Centroid(triangle [, out])
-
Calculates the position of a Triangle's centroid, which is also its center of mass (center of gravity).
The centroid is the point in a Triangle at which its three medians (the lines drawn from the vertices to the bisectors of the opposite sides) meet. It divides each one in a 2:1 ratio.
Parameters:
Name Type Argument Description trianglePhaser.Geom.Triangle The Triangle to use.
outPhaser.Geom.Point | object <optional>
An object to store the coordinates in.
- Since: 3.0.0
- Source: src/geom/triangle/Centroid.js (Line 13)
Returns:
The
outobject with modifiedxandyproperties, or a new Point if none was provided.- Type
- Phaser.Geom.Point | object
-
<static> CircumCenter(triangle [, out])
-
Computes the circumcentre of a triangle. The circumcentre is the centre of the circumcircle, the smallest circle which encloses the triangle. It is also the common intersection point of the perpendicular bisectors of the sides of the triangle, and is the only point which has equal distance to all three vertices of the triangle.
Parameters:
Name Type Argument Description trianglePhaser.Geom.Triangle The Triangle to get the circumcenter of.
outPhaser.Math.Vector2 <optional>
The Vector2 object to store the position in. If not given, a new Vector2 instance is created.
- Since: 3.0.0
- Source: src/geom/triangle/CircumCenter.js (Line 30)
Returns:
A Vector2 object holding the coordinates of the circumcenter of the Triangle.
- Type
- Phaser.Math.Vector2
-
<static> CircumCircle(triangle [, out])
-
Finds the circumscribed circle (circumcircle) of a Triangle object. The circumcircle is the circle which touches all of the triangle's vertices.
Parameters:
Name Type Argument Description trianglePhaser.Geom.Triangle The Triangle to use as input.
outPhaser.Geom.Circle <optional>
An optional Circle to store the result in.
- Since: 3.0.0
- Source: src/geom/triangle/CircumCircle.js (Line 11)
Returns:
The updated
outCircle, or a new Circle if none was provided.- Type
- Phaser.Geom.Circle
-
<static> Clone(source)
-
Clones a Triangle object.
Parameters:
Name Type Description sourcePhaser.Geom.Triangle The Triangle to clone.
- Since: 3.0.0
- Source: src/geom/triangle/Clone.js (Line 9)
Returns:
A new Triangle identical to the given one but separate from it.
- Type
- Phaser.Geom.Triangle
-
<static> Contains(triangle, x, y)
-
Checks if a point (as a pair of coordinates) is inside a Triangle's bounds.
Parameters:
Name Type Description trianglePhaser.Geom.Triangle The Triangle to check.
xnumber The X coordinate of the point to check.
ynumber The Y coordinate of the point to check.
- Since: 3.0.0
- Source: src/geom/triangle/Contains.js (Line 9)
Returns:
trueif the point is inside the Triangle, otherwisefalse.- Type
- boolean
-
<static> ContainsArray(triangle, points [, returnFirst] [, out])
-
Filters an array of point-like objects to only those contained within a triangle. If
returnFirstis true, will return an array containing only the first point in the provided array that is within the triangle (or an empty array if there are no such points).Parameters:
Name Type Argument Default Description trianglePhaser.Geom.Triangle The triangle that the points are being checked in.
pointsArray.<Phaser.Geom.Point> An array of point-like objects (objects that have an
xandyproperty)returnFirstboolean <optional>
false If
true, return an array containing only the first point found that is within the triangle.outarray <optional>
If provided, the points that are within the triangle will be appended to this array instead of being added to a new array. If
returnFirstis true, only the first point found within the triangle will be appended. This array will also be returned by this function.- Since: 3.0.0
- Source: src/geom/triangle/ContainsArray.js (Line 13)
Returns:
An array containing all the points from
pointsthat are within the triangle, if an array was provided asout, points will be appended to that array and it will also be returned here.- Type
- Array.<Phaser.Geom.Point>
-
<static> ContainsPoint(triangle, point)
-
Tests if a triangle contains a point.
Parameters:
Name Type Description trianglePhaser.Geom.Triangle The triangle.
pointPhaser.Geom.Point | Phaser.Math.Vector2 | any The point to test, or any point-like object with public
xandyproperties.- Since: 3.0.0
- Source: src/geom/triangle/ContainsPoint.js (Line 9)
Returns:
trueif the point is within the triangle, otherwisefalse.- Type
- boolean
-
<static> CopyFrom(source, dest)
-
Copy the values of one Triangle to a destination Triangle.
Parameters:
Name Type Description sourcePhaser.Geom.Triangle The source Triangle to copy the values from.
destPhaser.Geom.Triangle The destination Triangle to copy the values to.
- Since: 3.0.0
- Source: src/geom/triangle/CopyFrom.js (Line 7)
Returns:
The destination Triangle.
- Type
- Phaser.Geom.Triangle
-
<static> Decompose(triangle [, out])
-
Decomposes a Triangle into an array of its points.
Parameters:
Name Type Argument Description trianglePhaser.Geom.Triangle The Triangle to decompose.
outarray <optional>
An array to store the points into.
- Since: 3.0.0
- Source: src/geom/triangle/Decompose.js (Line 7)
Returns:
The provided
outarray, or a new array if none was provided, with three objects withxandyproperties representing each point of the Triangle appended to it.- Type
- array
-
<static> Equals(triangle, toCompare)
-
Returns true if two triangles have the same coordinates.
Parameters:
Name Type Description trianglePhaser.Geom.Triangle The first triangle to check.
toComparePhaser.Geom.Triangle The second triangle to check.
- Since: 3.0.0
- Source: src/geom/triangle/Equals.js (Line 7)
Returns:
trueif the two given triangles have the exact same coordinates, otherwisefalse.- Type
- boolean
-
<static> GetPoint(triangle, position [, out])
-
Returns a Point from around the perimeter of a Triangle.
Parameters:
Name Type Argument Description trianglePhaser.Geom.Triangle The Triangle to get the point on its perimeter from.
positionnumber The position along the perimeter of the triangle. A value between 0 and 1.
outPhaser.Geom.Point | object <optional>
An option Point, or Point-like object to store the value in. If not given a new Point will be created.
- Since: 3.0.0
- Source: src/geom/triangle/GetPoint.js (Line 10)
Returns:
A Point object containing the given position from the perimeter of the triangle.
- Type
- Phaser.Geom.Point | object
-
<static> GetPoints(triangle, quantity, stepRate [, out])
-
Returns an array of evenly spaced points on the perimeter of a Triangle.
Parameters:
Name Type Argument Description trianglePhaser.Geom.Triangle The Triangle to get the points from.
quantitynumber The number of evenly spaced points to return. Set to 0 to return an arbitrary number of points based on the
stepRate.stepRatenumber If
quantityis 0, the distance between each returned point.outarray | Array.<Phaser.Geom.Point> <optional>
An array to which the points should be appended.
- Since: 3.0.0
- Source: src/geom/triangle/GetPoints.js (Line 10)
Returns:
The modified
outarray, or a new array if none was provided.- Type
- array | Array.<Phaser.Geom.Point>
-
<static> InCenter(triangle [, out])
-
Calculates the position of the incenter of a Triangle object. This is the point where its three angle bisectors meet and it's also the center of the incircle, which is the circle inscribed in the triangle.
Parameters:
Name Type Argument Description trianglePhaser.Geom.Triangle The Triangle to find the incenter of.
outPhaser.Geom.Point <optional>
An optional Point in which to store the coordinates.
- Since: 3.0.0
- Source: src/geom/triangle/InCenter.js (Line 21)
Returns:
Point (x, y) of the center pixel of the triangle.
- Type
- Phaser.Geom.Point
-
<static> Offset(triangle, x, y)
-
Moves each point (vertex) of a Triangle by a given offset, thus moving the entire Triangle by that offset.
Parameters:
Name Type Description trianglePhaser.Geom.Triangle The Triangle to move.
xnumber The horizontal offset (distance) by which to move each point. Can be positive or negative.
ynumber The vertical offset (distance) by which to move each point. Can be positive or negative.
- Since: 3.0.0
- Source: src/geom/triangle/Offset.js (Line 7)
Returns:
The modified Triangle.
- Type
- Phaser.Geom.Triangle
-
<static> Perimeter(triangle)
-
Gets the length of the perimeter of the given triangle. Calculated by adding together the length of each of the three sides.
Parameters:
Name Type Description trianglePhaser.Geom.Triangle The Triangle to get the length from.
- Since: 3.0.0
- Source: src/geom/triangle/Perimeter.js (Line 9)
Returns:
The length of the Triangle.
- Type
- number
-
<static> Random(triangle [, out])
-
Returns a random Point from within the area of the given Triangle.
Parameters:
Name Type Argument Description trianglePhaser.Geom.Triangle The Triangle to get a random point from.
outPhaser.Geom.Point <optional>
The Point object to store the position in. If not given, a new Point instance is created.
- Since: 3.0.0
- Source: src/geom/triangle/Random.js (Line 9)
Returns:
A Point object holding the coordinates of a random position within the Triangle.
- Type
- Phaser.Geom.Point
-
<static> Rotate(triangle, angle)
-
Rotates a Triangle about its incenter, which is the point at which its three angle bisectors meet.
Parameters:
Name Type Description trianglePhaser.Geom.Triangle The Triangle to rotate.
anglenumber The angle by which to rotate the Triangle, in radians.
- Since: 3.0.0
- Source: src/geom/triangle/Rotate.js (Line 10)
Returns:
The rotated Triangle.
- Type
- Phaser.Geom.Triangle
-
<static> RotateAroundPoint(triangle, point, angle)
-
Rotates a Triangle at a certain angle about a given Point or object with public
xandyproperties.Parameters:
Name Type Description trianglePhaser.Geom.Triangle The Triangle to rotate.
pointPhaser.Geom.Point The Point to rotate the Triangle about.
anglenumber The angle by which to rotate the Triangle, in radians.
- Since: 3.0.0
- Source: src/geom/triangle/RotateAroundPoint.js (Line 9)
Returns:
The rotated Triangle.
- Type
- Phaser.Geom.Triangle
-
<static> RotateAroundXY(triangle, x, y, angle)
-
Rotates an entire Triangle at a given angle about a specific point.
Parameters:
Name Type Description trianglePhaser.Geom.Triangle The Triangle to rotate.
xnumber The X coordinate of the point to rotate the Triangle about.
ynumber The Y coordinate of the point to rotate the Triangle about.
anglenumber The angle by which to rotate the Triangle, in radians.
- Since: 3.0.0
- Source: src/geom/triangle/RotateAroundXY.js (Line 7)
Returns:
The rotated Triangle.
- Type
- Phaser.Geom.Triangle
-
contains(x, y)
-
Checks whether a given points lies within the triangle.
Parameters:
Name Type Description xnumber The x coordinate of the point to check.
ynumber The y coordinate of the point to check.
- Since: 3.0.0
- Source: src/geom/triangle/Triangle.js (Line 118)
Returns:
trueif the coordinate pair is within the triangle, otherwisefalse.- Type
- boolean
-
getLineA( [line])
-
Returns a Line object that corresponds to Line A of this Triangle.
Parameters:
Name Type Argument Description linePhaser.Geom.Line <optional>
A Line object to set the results in. If
undefineda new Line will be created.- Since: 3.0.0
- Source: src/geom/triangle/Triangle.js (Line 224)
Returns:
A Line object that corresponds to line A of this Triangle.
- Type
- Phaser.Geom.Line
-
getLineB( [line])
-
Returns a Line object that corresponds to Line B of this Triangle.
Parameters:
Name Type Argument Description linePhaser.Geom.Line <optional>
A Line object to set the results in. If
undefineda new Line will be created.- Since: 3.0.0
- Source: src/geom/triangle/Triangle.js (Line 245)
Returns:
A Line object that corresponds to line B of this Triangle.
- Type
- Phaser.Geom.Line
-
getLineC( [line])
-
Returns a Line object that corresponds to Line C of this Triangle.
Parameters:
Name Type Argument Description linePhaser.Geom.Line <optional>
A Line object to set the results in. If
undefineda new Line will be created.- Since: 3.0.0
- Source: src/geom/triangle/Triangle.js (Line 266)
Returns:
A Line object that corresponds to line C of this Triangle.
- Type
- Phaser.Geom.Line
-
getPoint(position [, output])
-
Returns a specific point on the triangle.
Parameters:
Name Type Argument Description positionnumber Position as float within
0and1.0equals the first point.outputPhaser.Geom.Point | object <optional>
Optional Point, or point-like object, that the calculated point will be written to.
- Since: 3.0.0
- Source: src/geom/triangle/Triangle.js (Line 134)
Returns:
Calculated
Pointthat represents the requested position. It is the same asoutputwhen this parameter has been given.- Type
- Phaser.Geom.Point | object
-
getPoints(quantity [, stepRate] [, output])
-
Calculates a list of evenly distributed points on the triangle. It is either possible to pass an amount of points to be generated (
quantity) or the distance between two points (stepRate).Parameters:
Name Type Argument Description quantitynumber Number of points to be generated. Can be falsey when
stepRateshould be used. All points have the same distance along the triangle.stepRatenumber <optional>
Distance between two points. Will only be used when
quantityis falsey.outputarray | Array.<Phaser.Geom.Point> <optional>
Optional Array for writing the calculated points into. Otherwise a new array will be created.
- Since: 3.0.0
- Source: src/geom/triangle/Triangle.js (Line 152)
Returns:
Returns a list of calculated
Pointinstances or the filled array passed as parameteroutput.- Type
- array | Array.<Phaser.Geom.Point>
-
getRandomPoint( [point])
-
Returns a random point along the triangle.
Parameters:
Name Type Argument Description pointPhaser.Geom.Point <optional>
Optional
Pointthat should be modified. Otherwise a new one will be created.- Since: 3.0.0
- Source: src/geom/triangle/Triangle.js (Line 171)
Returns:
Random
Point. When parameterpointhas been provided it will be returned.- Type
- Phaser.Geom.Point
-
setTo( [x1] [, y1] [, x2] [, y2] [, x3] [, y3])
-
Sets all three points of the triangle. Leaving out any coordinate sets it to be
0.Parameters:
Name Type Argument Default Description x1number <optional>
0 xcoordinate of the first point.y1number <optional>
0 ycoordinate of the first point.x2number <optional>
0 xcoordinate of the second point.y2number <optional>
0 ycoordinate of the second point.x3number <optional>
0 xcoordinate of the third point.y3number <optional>
0 ycoordinate of the third point.- Since: 3.0.0
- Source: src/geom/triangle/Triangle.js (Line 188)
Returns:
This Triangle object.
- Type
- Phaser.Geom.Triangle
