# euclid.ts

2D Euclidean geometry classes, utilities, and drawing tools.

## Angle

### ClassAngle

A 2-dimensional angle class, defined by three points.

#### constructor

• new Angle(a: Point, b: Point, c: Point): Angle

#### Accessorarc

Returns the Arc element corresponding to this angle.

• get arc()

#### Accessorbisector

The bisector of this angle.

• get bisector()

#### Accessordeg

The size, in degrees, of this angle.

• get deg()

#### AccessorisRight

Checks if this angle is right-angled.

• get isRight()

The size, in radians, of this angle.

#### Accessorsup

Returns the smaller one of this and its supplementary angle.

• get sup()

• at(): Point

#### Methodcontains

• contains(): boolean

#### Methodequals

• equals(_a: Angle): boolean

#### Methodproject

• project(): Point

#### Methodreflect

• reflect(l: Line): Angle

#### Methodrotate

• rotate(a: number, c?: SimplePoint): Angle

#### Methodscale

• scale(sx: number, sy?: number): Angle

#### Methodshift

• shift(x: number, y?: number): Angle

#### Methodtransform

• transform(m: TransformMatrix): Angle

#### Methodtranslate

• translate(p: Point): Angle

## Arc

### ClassArc

An arc segment of a circle, with given center, start point and angle.

#### constructor

• new Arc(c: Point, start: Point, angle: number): Arc

• get center()

• get end()

• get major()

• get minor()

#### AccessorstartAngle

• get startAngle()

#### Methodat

• at(t: number): Point

#### Methodcontains

• contains(_p: Point): boolean

#### Methodcontract

• contract(p: number): this

#### Methodequals

• equals(): boolean

#### Methodproject

• project(p: Point): Point

#### Methodreflect

• reflect(l: Line): this

#### Methodrotate

• rotate(a: number, c?: Point): this

#### Methodscale

• scale(sx: number, sy?: number): this

#### Methodshift

• shift(x: number, y?: number): this

#### Methodtransform

• transform(m: TransformMatrix): this

#### Methodtranslate

• translate(p: Point): this

## Bounds

### ClassBounds

#### constructor

• new Bounds(xMin: number, xMax: number, yMin: number, yMax: number): Bounds

• get dx()

• get dy()

• get rect()

• get xRange()

• get yRange()

## Circle

### ClassCircle

A circle with a given center and radius.

#### constructor

• new Circle(c?: Point, r?: number): Circle

• get arc()

#### Accessorarea

The area of this circle.

• get area()

#### Accessorcircumference

The length of the circumference of this circle.

• get circumference()

#### Methodat

• at(t: number): Point

#### Methodcontains

• contains(p: Point): boolean

#### Methodequals

• equals(other: Circle): boolean

#### Methodproject

• project(p: Point): Point

#### Methodreflect

• reflect(l: Line): Circle

#### Methodrotate

• rotate(a: number, c?: Point): Circle

#### Methodscale

• scale(sx: number, sy?: number): Circle

#### Methodshift

• shift(x: number, y?: number): Circle

#### MethodtangentAt

• tangentAt(t: number): Line

#### Methodtransform

• transform(m: TransformMatrix): Circle

#### Methodtranslate

• translate(p: Point): Circle

## Draw Canvas

### FunctiondrawCanvas

• drawCanvas(ctx: CanvasRenderingContext2D, obj: GeoElement, options?: CanvasDrawingOptions): void

## Draw Svg

### FunctionangleSize

• angleSize(angle: Angle, options?: SVGDrawingOptions): number

### FunctiondrawSVG

• drawSVG(obj: GeoElement, options?: SVGDrawingOptions): string

## Ellipse

### ClassEllipse

#### constructor

• new Ellipse(c: Point, a: number, b: number): Ellipse

#### Methodat

• at(t: number): Point

#### Methodcontains

• contains(_p: Point): boolean

#### Methodequals

• equals(): boolean

#### Methodintersect

• intersect(line: Line): Point[]

#### MethodnormalAt

• normalAt(p: Point): Line

#### Methodproject

• project(p: Point): Point

#### Methodreflect

• reflect(_l: Line): this

#### Methodrotate

• rotate(_a: number, _c?: Point): this

#### Methodscale

• scale(_sx: number, _sy?: number): this

#### Methodshift

• shift(_x: number, _y?: number): this

#### Methodtransform

• transform(_m: TransformMatrix): this

#### Methodtranslate

• translate(_p: Point): this

#### staticMethodfromFoci

• fromFoci(f1: Point, f2: Point, stringLength: number): Ellipse

## Intersection

### Functionintersections

• intersections(...elements: GeoShape[]): Point[]

## Line

### ClassLine

An infinite straight line that goes through two points.

#### constructor

• new Line(p1: Point, p2: Point): Line

#### Accessorangle

The angle formed between this line and the x-axis.

• get angle()

#### Accessorintercept

The y-axis intercept of this line.

• get intercept()

• get length()

#### AccessorlengthSquared

• get lengthSquared()

#### Accessormidpoint

The midpoint of this line.

• get midpoint()

#### AccessorperpendicularBisector

The perpendicular bisector of this line.

• get perpendicularBisector()

#### AccessorperpendicularVector

The point representing the perpendicular vector of this line.

• get perpendicularVector()

#### Accessorslope

The slope of this line.

• get slope()

#### AccessorunitVector

The point representing a unit vector along this line.

• get unitVector()

#### Methodat

• at(t: number): Point

#### Methodcontains

• contains(p: Point): boolean

#### MethoddistanceSquared

• distanceSquared(p: Point): number

#### Methodequals

• equals(other: Line): boolean

#### Methodmake

• make(p1: Point, p2: Point): Line

#### Methodparallel

• parallel(p: Point): Line

#### Methodperpendicular

• perpendicular(p: Point): Line

#### Methodproject

• project(p: SimplePoint): Point

#### Methodreflect

• reflect(l: Line): this

#### Methodrotate

• rotate(a: number, c?: Point): this

#### Methodscale

• scale(sx: number, sy?: number): Line

#### Methodshift

• shift(x: number, y?: number): Line

#### Methodtransform

• transform(m: TransformMatrix): this

#### Methodtranslate

• translate(p: Point): Line

### ClassRay

An infinite ray defined by an endpoint and another point on the ray.

#### Methodequals

• equals(other: Ray): boolean

#### Methodmake

• make(p1: Point, p2: Point): Ray

### ClassSegment

A finite line segment defined by its two endpoints.

#### Methodcontains

• contains(p: Point): boolean

#### Methodcontract

• contract(x: number): Segment

#### Methodequals

• equals(other: Segment, oriented?: boolean): boolean

#### Methodmake

• make(p1: Point, p2: Point): Segment

#### Methodproject

• project(p: SimplePoint): Point

## Point

### ClassPoint

A single point class defined by two coordinates x and y.

#### constructor

• new Point(x?: number, y?: number): Point

• get array()

• get flip()

#### Accessorinverse

• get inverse()

• get length()

#### Accessorperpendicular

• get perpendicular()

#### AccessorunitVector

• get unitVector()

#### Methodangle

• angle(c?: Point): number

#### MethodchangeCoordinates

• changeCoordinates(originCoords: Bounds, targetCoords: Bounds): Point

#### Methodclamp

• clamp(bounds: Bounds, padding?: number): Point

#### MethoddistanceFromLine

• distanceFromLine(l: Line): number

#### Methodequals

• equals(other: any): boolean

#### Methodfloor

• floor(): Point

#### Methodmod

• mod(x: number, y?: number): Point

#### Methodreflect

• reflect(l: Line): Point

#### Methodrotate

• rotate(angle: number, c?: SimplePoint): Point

#### Methodround

• round(inc?: number): Point

#### Methodscale

• scale(sx: number, sy?: number): Point

#### Methodshift

• shift(x: number, y?: number): Point

#### Methodsubtract

• subtract(p: SimplePoint): Point

#### Methodtransform

• transform(m: TransformMatrix): Point

#### Methodtranslate

• translate(p: Point): Point

#### staticMethodaverage

• average(...points: SimplePoint[]): Point

#### staticMethoddifference

• difference(p1: SimplePoint, p2: SimplePoint): Point

#### staticMethoddistance

• distance(p1: SimplePoint, p2: SimplePoint): number

#### staticMethoddot

• dot(p1: SimplePoint, p2: SimplePoint): number

#### staticMethodfromPolar

• fromPolar(angle: number, r?: number): Point

#### staticMethodinterpolate

• interpolate(p1: SimplePoint, p2: SimplePoint, t?: number): Point

#### staticMethodinterpolateList

• interpolateList(points: SimplePoint[], t?: number): Point

#### staticMethodmanhattan

• manhattan(p1: SimplePoint, p2: SimplePoint): number

#### staticMethodsum

• sum(p1: SimplePoint, p2: SimplePoint): Point

## Polygon

### ClassPolygon

A polygon defined by its vertex points.

#### constructor

• new Polygon(...points: Point[]): Polygon

• get area()

#### Accessorcentroid

• get centroid()

#### Accessorcircumference

• get circumference()

• get edges()

#### Accessororiented

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

• get oriented()

#### AccessorsignedArea

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

• get signedArea()

#### Methodat

• at(t: number): Point

#### Methodcontains

• contains(p: Point): boolean

#### Methodequals

• equals(_other: Polygon): boolean

#### Methodintersect

• intersect(polygon: Polygon): undefined | Polygon

#### Methodproject

• project(p: Point): Point

#### Methodreflect

• reflect(line: Line): this

#### Methodrotate

• rotate(a: number, center?: Point): this

#### Methodscale

• scale(sx: number, sy?: number): this

#### Methodshift

• shift(x: number, y?: number): this

#### Methodtransform

• transform(m: TransformMatrix): this

#### Methodtranslate

• translate(p: Point): this

#### staticMethodcollision

• collision(p1: Polygon, p2: Polygon): boolean

#### staticMethodinterpolate

• interpolate(p1: Polygon, p2: Polygon, t?: number): Polygon

#### staticMethodregular

• regular(n: number, radius?: number): Polygon

### ClassPolyline

A polyline defined by its vertex points.

• get edges()

• get length()

### ClassTriangle

A triangle defined by its three vertices.

#### Accessorcircumcircle

• get circumcircle()

#### Accessorincircle

• get incircle()

#### Accessororthocenter

• get orthocenter()

## Rectangle

### ClassRectangle

A rectangle, defined by its top left vertex, width and height.

#### constructor

• new Rectangle(p: Point, w?: number, h?: number): Rectangle

• get area()

• get center()

#### Accessorcentroid

• get centroid()

#### Accessorcircumference

• get circumference()

• get edges()

• get points()

#### Accessorpolygon

A polygon class representing this rectangle.

• get polygon()

#### Methodat

• at(_t: number): Point

#### Methodcontains

• contains(p: Point): boolean

#### Methodequals

• equals(_other: Polygon): boolean

#### Methodproject

• project(p: SimplePoint): Point

#### Methodreflect

• reflect(l: Line): Polygon

#### Methodrotate

• rotate(a: number, c?: Point): Polygon

#### Methodscale

• scale(sx: number, sy?: number): Rectangle

#### Methodshift

• shift(x: number, y?: number): Rectangle

#### Methodtransform

• transform(m: TransformMatrix): Polygon

#### Methodtranslate

• translate(p: Point): Rectangle

#### staticMethodaroundPoints

• aroundPoints(...points: Point[]): Rectangle

## Types

### FunctionisAngle

• isAngle(shape: GeoElement): shape is Angle

### FunctionisArc

• isArc(shape: GeoElement): shape is Arc

### FunctionisCircle

• isCircle(shape: GeoElement): shape is Circle

### FunctionisLine

• isLine(shape: GeoElement): shape is Line

### FunctionisLineLike

• isLineLike(shape: GeoElement): shape is Line | Ray | Segment

### FunctionisPoint

• isPoint(shape: GeoElement): shape is Point

### FunctionisPolygon

• isPolygon(shape: GeoElement): shape is Polygon

### FunctionisPolygonLike

• isPolygonLike(shape: GeoElement): shape is Polygon | Rectangle

### FunctionisPolyline

• isPolyline(shape: GeoElement): shape is Polyline

### FunctionisRay

• isRay(shape: GeoElement): shape is Ray

### FunctionisRectangle

• isRectangle(shape: GeoElement): shape is Rectangle

### FunctionisSector

• isSector(shape: GeoElement): shape is Sector

### FunctionisSegment

• isSegment(shape: GeoElement): shape is Segment

## Utilities

### InterfaceGeoElement

#### Methodequals

• equals(other: GeoElement, oriented?: undefined | false | true): boolean

#### Methodreflect

• reflect(l: Line): GeoElement

#### Methodrotate

• rotate(angle: number, center?: SimplePoint): GeoElement

#### Methodscale

• scale(sx: number, sy?: undefined | number): GeoElement

#### Methodshift

• shift(x: number, y?: undefined | number): GeoElement

#### Methodtransform

• transform(matrix: TransformMatrix): GeoElement

#### Methodtranslate

• translate(p: Point): GeoElement

### InterfaceGeoShape

#### Methodat

• at(t: number): Point

#### Methodcontains

• contains(p: Point): boolean

#### Methodproject

• project(p: Point): Point