Convert degrees to radians
Multiply by π and divide by 180.
function degreesToRadians(degrees) { return degrees * Math.PI / 180; }mathCollection · 14 utilities
Angles and rectangles: small geometric helpers with explicit coordinate conventions and floating-point caveats.
Multiply by π and divide by 180.
function degreesToRadians(degrees) { return degrees * Math.PI / 180; }mathCompare corners: a contains b when b’s corners sit inside or on a’s edges.
function contains({ a, b }) { return a.x1 <= b.x1 && a.y1 <= b.y1 && a.x2 >= b.x2 && a.y2 >= b.…mathTwo rectangles overlap when they overlap on both axes.
function overlaps({ a, b }) { return a.x1 < b.x2 && b.x1 < a.x2 && a.y1 < b.y2 && b.y1 < a.y2; …mathUse Math.atan2 for the angle from the x axis, in radians or degrees.
function angle({ p1, p2, unit = 'radians' }) { const radians = Math.atan2(p2.y - p1.y, p2.x - p…mathApply the Pythagorean theorem with Math.hypot.
function distance({ p1, p2 }) { return Math.hypot(p2.x - p1.x, p2.y - p1.y); }mathBlend from a to b by an amount between 0 and 1.
function lerp({ a, b, amount }) { return (1 - amount) * a + amount * b; }mathMap a value in [min, max] to [0, 1].
function normalizeRatio({ value, min, max }) { return (value - min) / (max - min); }mathAverage the x and y coordinates.
function midpoint({ p1, p2 }) { return [(p1.x + p2.x) / 2, (p1.y + p2.y) / 2]; }mathCompare the point with the rectangle’s edges.
function isInside({ point, rect }) { return point.x > rect.left && point.x < rect.right && poin…mathDivide, round and multiply back.
function roundNearest({ value, nearest }) { return Math.round(value / nearest) * nearest; }mathMultiply by 180 and divide by π.
function radiansToDegrees(radians) { return radians * 180 / Math.PI; }mathAverage the two ends of a [from, to] range.
function rangeMidpoint([from, to]) { return (from + to) / 2; }mathMap a value from one range onto another.
function linearScale({ value, inMin, inMax, outMin, outMax }) { return ((value - inMin) * (outM…mathThe arrow-function form of the same mapping.
function scale({ value, from, to }) { return ((value - from[0]) * (to[1] - to[0])) / (from[1] -…mathTry a function in the local code lab, then read its limits before using it in an application.