Options
All
• Public
• Public/Protected
• All

# Class Geom

Geom class provides various helper functions for basic geometric operations

• Geom

## Methods

### Static anchor

• anchor(pts: GroupLike, ptOrIndex?: PtLike | number, direction?: "to" | "from"): void
• Given an anchor Pt, rebase all Pts in this group either to or from this anchor base.

#### Parameters

• ##### pts: GroupLike

a Group or array of Pt

• ##### Default value ptOrIndex: PtLike | number = 0

an index for the Pt array, or an external Pt

• ##### Default value direction: "to" | "from" = "to"

"to" (subtract all Pt with this anchor base) or "from" (add all Pt from this anchor base)

### Static boundAngle

• boundAngle(angle: number): number
• Bound an angle between 0 to 360 degrees

#### Returns number

• Bound a radian between 0 to 2-PI

### Static boundingBox

• Get a bounding box for a set of Pts

#### Parameters

• ##### pts: GroupLike

a Group or an array of Pts

#### Returns Group

a Group of two Pts, representing the top-left and bottom-right corners.

### Static centroid

• Get a centroid (the average middle point) for a set of Pts

#### Parameters

• ##### pts: GroupLike | number[][]

a Group or an array of Pts

#### Returns Pt

a centroid Pt

### Static cosTable

• cosTable(): object
• Generate a sine and cosine lookup table

#### Returns object

an object with 2 tables (array of 360 values) and 2 functions to get sin/cos given a radian parameter. { sinTable:Float64Array, cosTable:Float64Array, sin:(rad)=>number, cos:(rad)=>number }

### Static interpolate

• interpolate(a: Pt | number[], b: Pt | number[], t?: number): Pt
• Get an interpolated (or extrapolated) value between two Pts

#### Parameters

first Pt

second Pt

• ##### Default value t: number = 0.5

a value between 0 to 1 to interpolate, or any other value to extrapolate

#### Returns Pt

interpolated point as a new Pt

### Static isPerpendicular

• Check if two Pts (vectors) are perpendicular to each other

### Static perpendicular

• perpendicular(pt: PtLike, axis?: string | number[]): Group
• Find two Pt that are perpendicular to this Pt (2D)

#### Parameters

• ##### Default value axis: string | number[] = Const.xy

a string such as "xy" (use Const.xy) or an array to specify index for two dimensions

#### Returns Group

an array of two Pt that are perpendicular to this Pt

### Static reflect2D

• Reflect a Pt or a Group of Pts along a 2D line

#### Parameters

• ##### ps: Pt | GroupLike

a Pt or a Group of Pts

• ##### line: GroupLike

a Group of 2 Pts that defines a line for reflection

• ##### Optional axis: string

optional axis such as "yz" to define a 2D plane of reflection

### Static rotate2D

• Rotate a Pt or a Group of Pts in 2D space

#### Parameters

• ##### ps: Pt | GroupLike

a Pt or a Group of Pts

• ##### angle: number

rotate angle

• ##### Optional anchor: PtLike

optional anchor point to rotate from

• ##### Optional axis: string

optional axis such as "yz" to define a 2D plane of rotation

### Static scale

• Scale a Pt or a Group of Pts

#### Parameters

• ##### ps: Pt | GroupLike

a Pt or a Group of Pts

• ##### scale: number | number[] | PtLike

scale value

• ##### Optional anchor: PtLike

optional anchor point to scale from

### Static shear2D

• Shear a Pt or a Group of Pts in 2D space

#### Parameters

• ##### ps: Pt | GroupLike

a Pt or a Group of Pts

• ##### scale: number | number[] | PtLike

shearing value which can be a number or an array of 2 numbers

• ##### Optional anchor: PtLike

optional anchor point to shear from

• ##### Optional axis: string

optional axis such as "yz" to define a 2D plane of shearing

### Static sinTable

• sinTable(): object
• Generate a sine and cosine lookup table

#### Returns object

an object with 2 tables (array of 360 values) and 2 functions to get sin/cos given a radian parameter. { sinTable:Float64Array, cosTable:Float64Array, sin:(rad)=>number, cos:(rad)=>number }

### Static toDegree

• Convert an angle in radian to degree

#### Returns number

• Convert an angle in degree to radian

### Static withinBound

• withinBound(pt: PtLike | number[], boundPt1: PtLike | number[], boundPt2: PtLike | number[]): boolean
• Check if a Pt is within the rectangular boundary defined by two Pts

#### Parameters

• ##### pt: PtLike | number[]

the Pt to check

• ##### boundPt1: PtLike | number[]

boundary Pt 1

• ##### boundPt2: PtLike | number[]

boundary Pt 2

#### Returns boolean

Generated using TypeDoc