Skip to content

Math

Type module

Sources

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

/**
* Import via main package
* Access items like: am5.math.myVariable
*/
import * as am5 from "@amcharts/amcharts5";
/**
* Import via: Math.ts
* Access items like: $math.myVariable
*/
import * as $math from "@amcharts/amcharts5/Math";

Variables

DEGREES

Type numberDefault 180 / Math.PI

HALFPI

Type numberDefault PI / 2

RADIANS

Type numberDefault Math.PI / 180

Functions

boundsOverlap(bounds1: IBounds,
bounds2: IBounds
)

Returns boolean

Returns true if two bounds overlap. Bounds that only touch do not.

ceil(value: number,
precision: number
)

Returns number

Rounds a number up to a whole number, or to precision decimal places if 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: 0 points right and angles grow clockwise. If point2 is omitted, returns the angle of point1 as seen from 0, 0.

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, relative to the circle's center.

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 a date down to the start of its period of count units, such as to midnight for "day". May change date itself.

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 tangent of an angle specified in degrees.