Overview of the Math
object¶
The Math
object is an extension of the standard Math
object in the JavaScript language and provides a range of useful mathematical functions.
Core Capabilities of Math
¶
- Comparison of numbers with floating-point precision (
isEpsilon
,isEqual
,isLessEqual
,isGreatEqual
). - Conversion of polar coordinates to Cartesian coordinates (
fromPolar
). - Functions for working with angular values (
rad
,deg
,normAngle
,middleAngle
,spanAngle
).
Tip
Use comparison functions instead of direct comparison ==
to avoid issues with precision.
Constants Math
¶
Constant | Description | Value |
---|---|---|
Math.EPSILON |
Minimum positive number, such that 1 + Math.EPSILON = 1 when working with floating-point numbers |
1e-7 |
Methods of the Math
object¶
Below is a list of the available methods provided by the Math
object. Click on a method name to see its detailed description and examples.
Method | Description |
---|---|
Math.deg() | Convert radians to degrees. |
Math.rad() | Convert degrees to radians. |
Math.fromPolar() | Convert coordinates of a point from polar coordinates (radius, angle) to Cartesian (x, y) . |
Math.normAngle() | Normalize the value of an angle, returns a value in the interval (0°, 360°). |
Math.spanAngle() | Distance between angles a₁ and a₂ . |
Math.middleAngle() | Calculate the average angle between a₁ and a₂ considering direction. |
Math.isEpsilon() | Returns true if the absolute value of arg ≤ eps . |
Math.isEqual() | Returns true if the difference between arg₁ and arg₂ ≤ eps . |
Math.isLessEqual() | Returns true if arg₁ ≤ arg₂ considering precision eps . |
Math.isGreatEqual() | Returns true if arg₁ ≥ arg₂ considering precision eps . |
Math.round() | Round a number to the specified precision. |
Overall Structure of the Math
object¶
graph LR
Parent[JS-Math] --> A[Math]
A[Math] --> B[Comparison of numbers]
A --> C[Conversion of coordinates]
A --> D[Working with angles]
B --> B1["isEpsilon()"]
B --> B2["isEqual()"]
B --> B3["isLessEqual()"]
B --> B4["isGreatEqual()"]
C --> C1["fromPolar()"]
D --> D1["rad()"]
D --> D2["deg()"]
D --> D3["normAngle()"]
D --> D4["middleAngle()"]
D --> D5["spanAngle()"]
%% === Styles === %%
%%classDef math fill:#f0f8ff,stroke:#3366cc,stroke-width:2px;
%%classDef compare fill:#fff5e6,stroke:#cc6600,stroke-width:2px;
%%classDef coords fill:#e6ffe6,stroke:#009933,stroke-width:2px;
%%classDef angles fill:#ffe6e6,stroke:#cc0052,stroke-width:2px;
%%classDef func fill:#ffffff,stroke:#aaaaaa,stroke-width:1px;
%%=== Applies styles to nodes === %%
%%class Parent,A math
%%class B compare
%%class C coords
%%class D angles
%%class B1,B2,B3,B4,C1,D1,D2,D3,D4 func
Last update: 8 August 2025, 10:36