Geom

Geom class provides static helper functions for basic geometric operations.

Class in src/Num.ts

Methods

STATIC anchor ( pts, ptOrIndex, direction )

Given an anchor Pt, rebase all Pts in this group either to or from this anchor base.

parameters
pts: PtLikeIterable

a Group or an Iterable

ptOrIndex: PtLike | number (default value: 0)

an index for the Pt array, or an external Pt

direction: to | from (default value: "to")

a string either "to" (subtract all Pt with this anchor base), or "from" (add all Pt from this anchor base)

returns
void

source

STATIC boundAngle ( angle )

Bound an angle between 0 to 360 degrees.

parameters
angle: number

angle value

returns
number

source

STATIC boundingBox ( pts )

Get a bounding box for a set of Pts.

parameters
pts: PtIterable

a Group or an Iterable

returns
Group

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

source

STATIC boundRadian ( radian )

Bound a radian between 0 to two PI.

parameters
radian: number

radian value

returns
number

source

STATIC centroid ( pts )

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

parameters
pts: PtLikeIterable

a Group or an Iterable

returns
Pt

a centroid Pt

source

STATIC cosTable ( )

Generate a cosine lookup table.

returns
{ cos:`find`, table:`Float64Array` }

an object with a cosine tables (array of 360 values) and a function to get cosine given a radian input.

source

STATIC interpolate ( a, b, t )

Get an interpolated (or extrapolated) value between two Pts. For linear interpolation between 2 scalar values, use Num.lerp.

parameters
a: PtLike

first Pt

b: PtLike

second Pt

t: number (default value: 0.5)

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

returns
Pt

interpolated point as a new Pt

source

STATIC isPerpendicular ( p1, p2 )

Check if two Pts are perpendicular to each other (2D only).

parameters
p1: PtLike

p2: PtLike

returns
boolean

source

STATIC perpendicular ( pt, axis )

Find two Pts that are perpendicular to this Pt (2D only).

parameters
pt: PtLike

axis: string | PtLike (default value: 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

source

STATIC reflect2D ( ps, line, axis )

Reflect a Pt or a Group of Pts along a 2D line. You may also use Pt.reflect2D instance method.

parameters
ps: Pt | PtIterable

either a single Pt, or a Group or an Iterable

line: PtLikeIterable

a Group or an Iterable that defines a line for reflection

axis: string | PtLike

optional axis such as "xy" (use Const.xy) to define a 2D plane, or a number array to specify indices

returns
Geom

source

STATIC rotate2D ( ps, angle, anchor, axis )

Rotate a Pt or a Group of Pts in 2D space. You may also use Pt.rotate2D instance method.

parameters
ps: Pt | PtIterable

either a single Pt, or a Group or an Iterable

angle: number

rotate angle

anchor: PtLike

optional anchor point to rotate from

axis: string | PtLike

optional axis such as "xy" (use Const.xy) to define a 2D plane, or a number array to specify indices

returns
Geom

source

STATIC scale ( ps, scale, anchor )

Scale a Pt or a Group of Pts. You may also use Pt.scale instance method.

parameters
ps: Pt | PtIterable

either a single Pt, or a Group or an Iterable

scale: number | PtLike

scale value

anchor: PtLike

optional anchor point to scale from

returns
Geom

source

STATIC shear2D ( ps, scale, anchor, axis )

Shear a Pt or a Group of Pts in 2D space. You may also use Pt.shear2D instance method.

parameters
ps: Pt | PtIterable

either a single Pt, or a Group or an Iterable

scale: number | PtLike

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

anchor: PtLike

optional anchor point to shear from

axis: string | PtLike

optional axis such as "xy" (use Const.xy) to define a 2D plane, or a number array to specify indices

returns
Geom

source

STATIC sinTable ( )

Generate a sine lookup table.

returns
{ sin:`find`, table:`Float64Array` }

an object with a sine tables (array of 360 values) and a function to get sine value given a radian input.

source

STATIC sortEdges ( pts )

Sort the Pts so that their edges will form a non-overlapping polygon. (Reference)

parameters
pts: PtIterable

a Group or an Iterable

returns
GroupLike

source

STATIC toDegree ( radian )

Convert an angle in radian to degree.

parameters
radian: number

radian value

returns
number

source

STATIC toRadian ( angle )

Convert an angle in degree to radian.

parameters
angle: number

angle value

returns
number

source

STATIC withinBound ( pt, boundPt1, boundPt2 )

Check if a Pt is within the rectangular boundary defined by two Pts.

parameters
pt: PtLike

the Pt to check

boundPt1: PtLike

boundary Pt 1

boundPt2: PtLike

boundary Pt 2

returns
boolean

source