Class: Polygon
Polygon is the representation of a 2D Polygon shape. Can be used in collision detection and rendering.
Implements
Table of contents
Constructors
Properties
Methods
- Apply4D
- Center
- Copy
- FarthestPointInDirection
- Free
- GetFloat32Array
- PointInside
- Transform
- EllipseEstimation
- QuadByDimensions
- QuadByPoints
- RectangleByDimensions
- RectangleByPoints
Constructors
constructor
+ new Polygon(points
: Float32Array | Vector[], wrap?
: boolean): Polygon
Parameters:
Name | Type | Default value |
---|---|---|
points |
Float32Array | Vector[] | - |
wrap |
boolean | false |
Returns: Polygon
Properties
points
• points: Float32Array
Methods
Apply4D
▸ Apply4D(matrix
: Matrix4D): Polygon
Parameters:
Name | Type |
---|---|
matrix |
Matrix4D |
Returns: Polygon
Center
▸ Center(): Vector
Center calculates/retrieves the center of a shape.
Returns: Vector
The center point of the shape
Implementation of: IShape
Copy
▸ Copy(): Polygon
Make a value copy of the Polygon.
Returns: Polygon
Implementation of: IShape
FarthestPointInDirection
▸ FarthestPointInDirection(direction
: Vector): Vector
FarthestPointInDirection returns the point that is farthest in the direction provided. Used in the GJK algorithm for collision detection.
Parameters:
Name | Type |
---|---|
direction |
Vector |
Returns: Vector
The farthest point in the direction provided
Implementation of: IShape
Free
▸ Free(): void
Free releases an object or it's constituent parts back into any available object pools.
Returns: void
Implementation of: IShape
GetFloat32Array
▸ GetFloat32Array(): Float32Array
GetFloat32Array converts the polygon to a WebGL/glMatrix compatible Float32Array
Returns: Float32Array
The array representation of the polygon
PointInside
▸ PointInside(point
: Vector): boolean
PointInside determines if a point provided is within the shape or not.
Parameters:
Name | Type |
---|---|
point |
Vector |
Returns: boolean
If the point is inside the shape, true = inside, false = outside
Implementation of: IShape
Transform
▸ Transform(transform
: Transform): Polygon
Transform takes a transform and applies it to shape.
Parameters:
Name | Type |
---|---|
transform |
Transform |
Returns: Polygon
The transformed shape
Implementation of: IShape
EllipseEstimation
▸ Static
EllipseEstimation(numOfPoints
: number, dimensions
: Vector, centerX?
: number, centerY?
: number, wrap?
: boolean): Polygon
EllipseEstimation provides a new polygon that estimates the shape of an ellipse.
Parameters:
Name | Type | Default value | Description |
---|---|---|---|
numOfPoints |
number | - | Number of points the estimation should have |
dimensions |
Vector | - | Ellipse dimensions |
centerX |
number | 0 | - |
centerY |
number | 0 | - |
wrap |
boolean | false | If the polygon should wrap on itself (first point == last point) |
Returns: Polygon
QuadByDimensions
▸ Static
QuadByDimensions(width
: number, height
: number, originX?
: number, originY?
: number): Polygon
QuadByDimensions returns a new polygon in a quad shape with the width and height provided, optionally around an origin point
Parameters:
Name | Type | Default value | Description |
---|---|---|---|
width |
number | - | Width of the quad |
height |
number | - | Height of the quad |
originX |
number | 0 | - |
originY |
number | 0 | - |
Returns: Polygon
QuadByPoints
▸ Static
QuadByPoints(bottomLeft
: Vector, topRight
: Vector): Polygon
QuadByPoints returns a new polygon in a quad shape between the two provided points.
Parameters:
Name | Type | Description |
---|---|---|
bottomLeft |
Vector | Bottom left of the quad |
topRight |
Vector | Top right of the quad |
Returns: Polygon
RectangleByDimensions
▸ Static
RectangleByDimensions(width
: number, height
: number, originX?
: number, originY?
: number, wrap?
: boolean): Polygon
RectangleByDimensions returns a new polygon in a rectangle shape with the width and height provided, optionally around an origin point.
Parameters:
Name | Type | Default value | Description |
---|---|---|---|
width |
number | - | Width of the rectangle |
height |
number | - | Height of the rectangle |
originX |
number | 0 | - |
originY |
number | 0 | - |
wrap |
boolean | false | - |
Returns: Polygon
RectangleByPoints
▸ Static
RectangleByPoints(bottomLeft
: Vector, topRight
: Vector, wrap?
: boolean): Polygon
RectangleByPoints returns a new polygon in a rectangle shape between the two provided points.
Parameters:
Name | Type | Default value | Description |
---|---|---|---|
bottomLeft |
Vector | - | Bottom left of the rectangle |
topRight |
Vector | - | Top right of the rectangle |
wrap |
boolean | false | - |
Returns: Polygon