Polygon

Class Polygon

A polygon defined by its vertex points.

Implements GeoShape

constructor (points: Array<Point>): Polygon

Name Type Default Description
points Array<Point>    

readonly Property .points

readonly Property .type : string

Default value: 'polygon'

Accessor .area : number

Accessor .centroid : Point

Accessor .circumference : number

Accessor .edges

Accessor .oriented : this

The oriented version of this polygon (vertices in clockwise order).

Accessor .radius : number

Accessor .signedArea : number

The (signed) area of this polygon. The result is positive if the vertices are ordered clockwise, and negative otherwise.

Method .at (t: number): Point

Name Type Default Description
t number    

Method .centerAt (on: Point): Polygon

Center this polygon on a given point or the origin

Name Type Default Description
on Point  

Method .contains (p: Point): boolean

Checks if a point p lies inside this polygon, by using a ray-casting algorithm and calculating the number of intersections.

Name Type Default Description
p Point    

Method .cut (line: Line): Array<Polygon>

Cut this polygon along a line, and return multiple parts.

Name Type Default Description
line Line    

Method .equals (other: Polygon, tolerance: number, oriented: boolean): boolean

Name Type Default Description
other Polygon    
tolerance number    
oriented boolean    

Method .offset (p: Point): number

Name Type Default Description
p Point    

Method .project (p: Point): Point

Name Type Default Description
p Point    

Method .reflect (line: Line): Polygon

Name Type Default Description
line Line    

Method .rotate (a: number, center: Point): Polygon

Rotates this polygon by a given angle (in radians), optionally around point center.

Name Type Default Description
a number    
center Point  

Method .scale (sx: number, sy: number): Polygon

Name Type Default Description
sx number    
sy number  

Method .shift (x: number, y: number): Polygon

Name Type Default Description
x number    
y number  

Method .toString (): string

Method .transform (m: TransformMatrix): Polygon

Name Type Default Description
m TransformMatrix    

Method .translate (p: SimplePoint): Polygon

Name Type Default Description
p SimplePoint    

static Method .collision (p1: Polygon, p2: Polygon): boolean

Checks if two polygons p1 and p2 collide.

Name Type Default Description
p1 Polygon    
p2 Polygon    

static Method .convexHull (points: Array<Point>): Polygon

Name Type Default Description
points Array<Point>    

static Method .interpolate (p1: Polygon, p2: Polygon, t: number): Polygon

Interpolates the points of two polygons

Name Type Default Description
p1 Polygon    
p2 Polygon    
t number 0.5  

static Method .regular (n: number, radius: number): Polygon

Creates a regular polygon.

Name Type Default Description
n number    
radius number 1  

static Method .union (polygons: Array<Polygon>): Array<Polygon>

Name Type Default Description
polygons Array<Polygon>    

Class Polyline

A polyline defined by its vertex points.

Extends Polygon

readonly Property .type

Default value: 'polyline'

Accessor .length : number

Method .toString (): string

Class Triangle

A triangle defined by its three vertices.

Extends Polygon

readonly Property .type

Default value: 'triangle'

Accessor .circumcircle

Accessor .incircle

Accessor .orthocenter : Point


Copyright © 2024 Mathigon.org