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: 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";

Variables

DEGREES

Type numberDefault 180 / PI

HALFPI

Type numberDefault PI / 2

RADIANS

Type numberDefault PI / 180

Functions

ceil(value: number,
precision?: number
)

Returns number

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

closest(values: number[],
referenceValue: number
)

Returns number

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

cos(value: number)

Returns number

Returns cosine of a number.

fitToRange(value: number,
minValue: $type.Optional <number>,
maxValue: $type.Optional <number>
)

Returns number

Adjust numeric value so it fits to specific value range.

getAngle(point1: IPoint,
point2?: IPoint
)

Returns number

Calculates 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 IPoint

Returns 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 IRectangle object representing a common rectangle that fits all passed in rectangles in it.

getCubicCurveDistance(point1: IPoint,
point2: IPoint,
controlPointA: IPoint,
controlPointB: IPoint,
stepCount: number
)

Returns number

Returns 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 number

Returns 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 number

Returns 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 IPoint

Returns an exact mid point between two points.

getRotation(point1: IPoint,
startPoint1: IPoint,
point2: IPoint,
startPoint2: IPoint
)

Returns number

Returns difference in angles between starting and ending position of two vectors.

getScale(point1: IPoint,
startPoint1: IPoint,
point2: IPoint,
startPoint2: IPoint
)

Returns number

Returns scale based on original and end position of the two points.

getVerticalDistance(point1: IPoint,
point2?: IPoint
)

Returns number

Returns 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 boolean

Checks 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 boolean

Returns true if a point is within rectangle

sin(value: number)

Returns number

Returns sine of a number.

stretch(t: number,
from: number,
to: number
)

Returns number

Stretches t so that it will always be between from and to.

tan(value: number)

Returns number

Returns tan of a number.

toNumberRange(value: any,
min: number,
max: number
)

Returns number

Converts any value and fits it into a specific value range.