Phaser.Math.Distance
Scope: static
Source: src/math/distance/index.js#L7
Static functions
Between
<static> Between(x1, y1, x2, y2)
Description:
Calculate the distance between two sets of coordinates (points).
Parameters:
| name | type | optional | description |
|---|---|---|---|
| x1 | number | No | The x coordinate of the first point. |
| y1 | number | No | The y coordinate of the first point. |
| x2 | number | No | The x coordinate of the second point. |
| y2 | number | No | The y coordinate of the second point. |
Returns: number - The distance between each point.
Source: src/math/distance/DistanceBetween.js#L7
Since: 3.0.0
BetweenPoints
<static> BetweenPoints(a, b)
Description:
Calculate the distance between two points.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| a | Phaser.Types.Math.Vector2Like | No | The first point. |
| b | Phaser.Types.Math.Vector2Like | No | The second point. |
Returns: number - The distance between the points.
Source: src/math/distance/DistanceBetweenPoints.js#L7
Since: 3.22.0
BetweenPointsSquared
<static> BetweenPointsSquared(a, b)
Description:
Calculate the squared distance between two points.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| a | Phaser.Types.Math.Vector2Like | No | The first point. |
| b | Phaser.Types.Math.Vector2Like | No | The second point. |
Returns: number - The squared distance between the points.
Source: src/math/distance/DistanceBetweenPointsSquared.js#L7
Since: 3.22.0
Chebyshev
<static> Chebyshev(x1, y1, x2, y2)
Description:
Calculate the Chebyshev distance between two sets of coordinates (points).
Chebyshev distance (or chessboard distance) is the maximum of the horizontal and vertical distances. It's the effective distance when movement can be horizontal, vertical, or diagonal.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| x1 | number | No | The x coordinate of the first point. |
| y1 | number | No | The y coordinate of the first point. |
| x2 | number | No | The x coordinate of the second point. |
| y2 | number | No | The y coordinate of the second point. |
Returns: number - The distance between each point.
Source: src/math/distance/DistanceChebyshev.js#L7
Since: 3.22.0
Power
<static> Power(x1, y1, x2, y2, [pow])
Description:
Calculate the distance between two sets of coordinates using the generalized power formula: sqrt((x2 - x1)^pow + (y2 - y1)^pow). When pow is 2 this is equivalent to standard Euclidean distance. Increasing pow emphasizes larger axis differences.
Parameters:
| name | type | optional | default | description |
|---|---|---|---|---|
| x1 | number | No | The x coordinate of the first point. | |
| y1 | number | No | The y coordinate of the first point. | |
| x2 | number | No | The x coordinate of the second point. | |
| y2 | number | No | The y coordinate of the second point. | |
| pow | number | Yes | 2 | The exponent applied to each axis difference. Defaults to 2, which gives standard Euclidean distance. |
Returns: number - The distance between the two points.
Source: src/math/distance/DistancePower.js#L7
Since: 3.0.0
Snake
<static> Snake(x1, y1, x2, y2)
Description:
Calculate the snake distance between two sets of coordinates (points).
Snake distance (rectilinear distance, Manhattan distance) is the sum of the horizontal and vertical distances. It's the effective distance when movement is allowed only horizontally or vertically (but not both).
Parameters:
| name | type | optional | description |
|---|---|---|---|
| x1 | number | No | The x coordinate of the first point. |
| y1 | number | No | The y coordinate of the first point. |
| x2 | number | No | The x coordinate of the second point. |
| y2 | number | No | The y coordinate of the second point. |
Returns: number - The distance between each point.
Source: src/math/distance/DistanceSnake.js#L7
Since: 3.22.0
Squared
<static> Squared(x1, y1, x2, y2)
Description:
Calculate the distance between two sets of coordinates (points), squared.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| x1 | number | No | The x coordinate of the first point. |
| y1 | number | No | The y coordinate of the first point. |
| x2 | number | No | The x coordinate of the second point. |
| y2 | number | No | The y coordinate of the second point. |
Returns: number - The distance between each point, squared.
Source: src/math/distance/DistanceSquared.js#L7
Since: 3.0.0