Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Geom

Geom class provides various helper functions for basic geometric operations

Hierarchy

  • Geom

Index

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)

    Returns void

Static boundAngle

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

    Parameters

    • angle: number

    Returns number

Static boundRadian

  • boundRadian(angle: number): number
  • Bound a radian between 0 to 2-PI

    Parameters

    • angle: number

    Returns number

Static boundingBox

  • Get a bounding box for a set of Pts

    Parameters

    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 }

    • cos: find
    • table: Float64Array

Static interpolate

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

    Parameters

    • a: Pt | number[]

      first Pt

    • b: Pt | number[]

      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

    Parameters

    Returns boolean

Static perpendicular

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

    Parameters

    • pt: PtLike
    • 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

    Returns Geom

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

    Returns Geom

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

    Returns Geom

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

    Returns Geom

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 }

    • sin: find
    • table: Float64Array

Static sortEdges

Static toDegree

  • toDegree(radian: number): number
  • Convert an angle in radian to degree

    Parameters

    • radian: number

    Returns number

Static toRadian

  • toRadian(angle: number): number
  • Convert an angle in degree to radian

    Parameters

    • angle: number

    Returns number

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