Math

Type module

Sources

Items from Math can be imported/included and used via following ways.

/**
 * --------------------------------------------------------
 * Import via main package: core.ts
 * Access items like: am5.math.myVariable
 *                    am5.math.myFunction()
 * --------------------------------------------------------
 */
import * as am5 from "@amcharts/amcharts5";

/**
 * --------------------------------------------------------
 * Import via: Math.ts
 * Access items like: $math.myVariable
 *                    $math.myFunction()
 * --------------------------------------------------------
 */
import * as $math from "@amcharts/amcharts5/Math";

/**
 * --------------------------------------------------------
 * Include via "index.js"
 * E.g.: "https://cdn.amcharts.com/lib/5/index.js"
 * Access items like: am5.math.myVariable
 *                    am5.math.myFunction()
 * --------------------------------------------------------
 */

Variables

RADIANS
#

Type number

Default PI / 180

HALFPI
#

Type number

Default PI / 2

DEGREES
#

Type number

Default 180 / PI

Functions

boundsOverlap(

bounds1: IBounds,
bounds2: IBounds

)

#

Returns boolean

Returns true if bounds overlap

ceil(

value: number,
precision: number

)

#

Returns number

Ceils the numeric value to whole number or specific precision of set.

circlesOverlap(

circle1: { radius: number,
  x: number,
  y: number }
,
circle2: { radius: number,
  x: number,
  y: number }

)

#

Returns boolean

Returns true if two circles overlap or touch.

closest(

values: number[],
referenceValue: number

)

#

Returns number

Returns the closest value from the array of values to the reference value.

cos(

angle: number

)

#

Returns number

Returns cosine of an angle specified in degrees.

fitAngleToRange(

value: number,
startAngle: number,
endAngle: number

)

#

Returns number

Fits an angle into the given start/end range, snapping to the nearest boundary when the angle falls outside.

fitToRange(

value: number,
min: number,
max: number

)

#

Returns number

Clamps a value to the given [min, max] range.

getAngle(

point1: IPoint,
point2?: IPoint

)

#

Returns number

Returns the angle in degrees from point1 to point2.

If point2 is omitted, uses double of point1 coordinates.

getArcBounds(

cx: number,
cy: number,
startAngle: number,
endAngle: number,
radius: number

)

#

Returns IBounds

Returns the bounding box of a circular arc.

getArcPoint(

radius: number,
arc: number

)

#

Returns { x: number,
  y: number }

Returns a point on a circle at the given angle.

getPointOnCubicCurve(

pointA: IPoint,
pointB: IPoint,
controlPointA: IPoint,
controlPointB: IPoint,
position: number

)

#

Returns IPoint

Returns a point on a cubic bezier curve at the given position (0–1).

getPointOnLine(

pointA: IPoint,
pointB: IPoint,
position: number

)

#

Returns IPoint

Returns a point at a relative position along a straight line between two points.

getPointOnQuadraticCurve(

pointA: IPoint,
pointB: IPoint,
controlPoint: IPoint,
position: number

)

#

Returns IPoint

Returns a point on a quadratic bezier curve at the given position (0–1).

inBounds(

point: IPoint,
bounds: IBounds

)

#

Returns boolean

Returns true if a point is inside the given bounds (inclusive).

mergeBounds(

bounds: IBounds[]

)

#

Returns IBounds

Merges an array of bounds into a single bounding box that encompasses all of them.

normalizeAngle(

value: number

)

#

Returns number

Normalizes an angle to the 0–360 range.

resolveLocationOnPath(

location: number,
cumulativeLengths: number[]

)

#

Returns { index: number,
  t: number }

Given a normalized location (0–1) along a multi-segment path and an array of cumulative segment lengths, returns which segment the location falls in and the local parameter t within that segment.

round(

value: number,
precision?: undefined | number,
floor?: undefined | false | true

)

#

Returns number

"Rounds" the date to specific time unit.

sin(

angle: number

)

#

Returns number

Returns sine of an angle specified in degrees.

spiralPoints(

cx: number,
cy: number,
radius: number,
radiusY: number,
innerRadius: number,
step: number,
radiusStep: number,
startAngle: number,
endAngle: number

)

#

Returns IPoint[]

Generates points along a spiral path.

tan(

angle: number

)

#

Returns number

Returns tan of an angle specified in degrees.