Class: Triangle

Triangle

A class to define a shape of a triangle via user defined coordinates.

Create a Triangle object with the x, y, x2, y2, x3, y3 properties.

import { Triangle } from 'pixi.js';

const triangle = new Triangle(0, 0, 100, 0, 50, 50);

new Triangle (x, y, x2, y2, x3, y3)

Name Type Default Description
x number 0

The X coord of the first point.

y number 0

The Y coord of the first point.

x2 number 0

The X coord of the second point.

y2 number 0

The Y coord of the second point.

x3 number 0

The X coord of the third point.

y3 number 0

The Y coord of the third point.

Implements

Members

type SHAPE_PRIMITIVE readonly

The type of the object, mainly used to avoid instanceof checks

Default Value:
  • 'triangle'

x number

The X coord of the first point.

Default Value:
  • 0

x2 number

The X coord of the second point.

Default Value:
  • 0

x3 number

The X coord of the third point.

Default Value:
  • 0

y number

The Y coord of the first point.

Default Value:
  • 0

y2 number

The Y coord of the second point.

Default Value:
  • 0

y3 number

The Y coord of the third point.

Default Value:
  • 0

Methods

Creates a clone of this Triangle

Returns:
Type Description
ShapePrimitive a copy of the triangle

contains (x, y) boolean

Checks whether the x and y coordinates given are contained within this triangle

Name Type Description
x number

The X coordinate of the point to test

y number

The Y coordinate of the point to test

Returns:
Type Description
boolean Whether the x/y coordinates are within this Triangle

copyFrom (triangle) this

Copies another triangle to this one.

Name Type Description
triangle Triangle

The triangle to copy from.

Returns:
Type Description
this Returns itself.

copyTo (triangle) Triangle

Copies this triangle to another one.

Name Type Description
triangle Triangle

The triangle to copy to.

Returns:
Type Description
Triangle Returns given parameter.

getBounds (out) Rectangle

Returns the framing rectangle of the triangle as a Rectangle object

Name Type Attributes Description
out Rectangle <optional>

optional rectangle to store the result

Returns:
Type Description
Rectangle The framing rectangle

strokeContains (pointX, pointY, strokeWidth) boolean

Checks whether the x and y coordinates given are contained within this triangle including the stroke.

Name Type Description
pointX number

The X coordinate of the point to test

pointY number

The Y coordinate of the point to test

strokeWidth number

The width of the line to check

Returns:
Type Description
boolean Whether the x/y coordinates are within this triangle