Math
Type module
Sources
Items from Math can be imported/included and used via following ways.
/** * Import via main package * Access items like: am4core.math.myVariable */import * as am4core from "@amcharts/amcharts4";
/** * Import via: Math.ts * Access items like: $math.myVariable */import * as $math from "@amcharts/amcharts4/Math";/** * Include via "core.js" * Access items like: am4core.math.myVariable */Variables
DEGREESType
numberDefault180 / PIHALFPIType
numberDefaultPI / 2RADIANSType
numberDefaultPI / 180
Functions
ceil(value:number,
precision?:number)Returns
numberCeils the numeric value to whole number or specific precision of set.
closest(values:number[],
referenceValue:number)Returns
numberReturns the closest value from the array of values to the reference value.
cos(value:number)Returns
numberReturns cosine of a number.
fitToRange(value:number,
minValue:$type.Optional<number>,
maxValue:$type.Optional<number>)Returns
numberAdjust numeric value so it fits to specific value range.
getAngle(point1:IPoint,
point2?:IPoint)Returns
numberCalculates angle of the vector based on two or one point.
getArcPoint(radius:number,
arc:number)Returns { x:
number, y:number}Returns point on arc
getBBox(points:IPoint[])Returns
$type.Optional<IRectangle>Converts an array of points into a bounding box rectangle.
Array can contain any number of points.
getCenterShift(center:IPoint,
point1:IPoint,
startPoint1:IPoint,
point2:IPoint,
startPoint2:IPoint)Returns
IPointReturns the shift in coordinates of the center when item is rotated, moved and scaled at the same time.
getCommonRectangle(rectangles:IRectangle[])Returns
$type.Optional<IRectangle>Returns a
IRectangleobject representing a common rectangle that fits all passed in rectangles in it.getCubicCurveDistance(point1:IPoint,
point2:IPoint,
controlPointA:IPoint,
controlPointB:IPoint,
stepCount:number)Returns
numberReturns approximate pixel "distance" between two points of cubic curveIf second point is not specified, distance from {x:0, y:0} point is calculated.
getDistance(point1:IPoint,
point2?:IPoint)Returns
numberReturns pixel "distance" between two points.
If second point is not specified, distance from {x:0, y:0} point is calculated.
getHorizontalDistance(point1:IPoint,
point2?:IPoint)Returns
numberReturns pixel "horizontal distance" between two points.
If second point is not specified, distance from {x:0, y:0} point is calculated.
getLineIntersection(pointA1:IPoint,
pointA2:IPoint,
pointB1:IPoint,
pointB2:IPoint)Returns { x:
number, y:number}getMidPoint(point1:IPoint,
point2:IPoint,
position?:number)Returns
IPointReturns an exact mid point between two points.
getRotation(point1:IPoint,
startPoint1:IPoint,
point2:IPoint,
startPoint2:IPoint)Returns
numberReturns difference in angles between starting and ending position of two vectors.
getScale(point1:IPoint,
startPoint1:IPoint,
point2:IPoint,
startPoint2:IPoint)Returns
numberReturns scale based on original and end position of the two points.
getVerticalDistance(point1:IPoint,
point2?:IPoint)Returns
numberReturns pixel "vertical distance" between two points.
If second point is not specified, distance from {x:0, y:0} point is calculated.
intersect(range1:IRange,
range2:IRange)Returns
booleanChecks whether two ranges of values intersect.
intersection(range1:IRange,
range2:IRange)Returns
$type.Optional<IRange>Returns an intersection range between two ranges of values.
invertRange(range:IRange)Returns { end:
number, start:number}Inverts the range of values.
isInRectangle(point:IPoint,
rectangle:IRectangle)Returns
booleanReturns true if a point is within rectangle
sin(value:number)Returns
numberReturns sine of a number.
stretch(t:number,
from:number,
to:number)Returns
numberStretches
tso that it will always be betweenfromandto.tan(value:number)Returns
numberReturns tan of a number.
toNumberRange(value:any,
min:number,
max:number)Returns
numberConverts any value and fits it into a specific value range.