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";/** * Include via "index.js" * Access items like: am5.math.myVariable */Variables
DEGREESType
numberDefault180 / Math.PIHALFPIType
numberDefaultPI / 2RADIANSType
numberDefaultMath.PI / 180
Functions
boundsOverlap(bounds1:IBounds,
bounds2:IBounds)Returns
booleanReturns
trueif two bounds overlap. Bounds that only touch do not.ceil(value:number,
precision:number)Returns
numberRounds a number up to a whole number, or to
precisiondecimal places if set.circlesOverlap(circle1: { radius:number, x:number, y:number},
circle2: { radius:number, x:number, y:number})Returns
booleanReturns
trueif two circles overlap or touch.closest(values:number[],
referenceValue:number)Returns
numberReturns the closest value from the array of values to the reference value.
cos(angle:number)Returns
numberReturns cosine of an angle specified in degrees.
fitAngleToRange(value:number,
startAngle:number,
endAngle:number)Returns
numberFits 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
numberClamps a value to the given [min, max] range.
getAngle(point1:IPoint,
point2?:IPoint)Returns
numberReturns the angle in degrees from
point1topoint2:0points right and angles grow clockwise. Ifpoint2is omitted, returns the angle ofpoint1as seen from0, 0.getArcBounds(cx:number,
cy:number,
startAngle:number,
endAngle:number,
radius:number)Returns
IBoundsReturns 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
IPointReturns a point on a cubic bezier curve at the given position (0–1).
getPointOnLine(pointA:IPoint,
pointB:IPoint,
position:number)Returns
IPointReturns a point at a relative position along a straight line between two points.
getPointOnQuadraticCurve(pointA:IPoint,
pointB:IPoint,
controlPoint:IPoint,
position:number)Returns
IPointReturns a point on a quadratic bezier curve at the given position (0–1).
inBounds(point:IPoint,
bounds:IBounds)Returns
booleanReturns
trueif a point is inside the given bounds (inclusive).mergeBounds(bounds:IBounds[])Returns
IBoundsMerges an array of bounds into a single bounding box that encompasses all of them.
normalizeAngle(value:number)Returns
numberNormalizes 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
numberRounds a date down to the start of its period of
countunits, such as to midnight for"day". May changedateitself.sin(angle:number)Returns
numberReturns 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
numberReturns tangent of an angle specified in degrees.