Geometry Functions (14)

Computational geometry, distances, coordinate transforms, polygons

area
Calculates the area of a polygon given its vertices using the shoelace formula. The vertices should be provided in order (clockwise or counterclockwise) as an array of 2D points.
Syntax
area(vertices)
Parameters
NameTypeDescription
verticesArrayArray of 2D points [[x0,y0],[x1,y1],...]
Returns
number — The area of the polygon
Examples
area([[0
0
See Also
distance convexHull
centroid
Computes the centroid of a polygon or point cloud. For polygons (3+ vertices), uses the signed-area weighted formula. For point clouds, returns the arithmetic mean of all coordinates.
Syntax
centroid(points)
Parameters
NameTypeDescription
pointsArrayArray of 2D points [[x0,y0],[x1,y1],...]
Returns
Array — Centroid as [cx, cy]
Examples
centroid([[0
0
chebyshevDistance
Calculates the Chebyshev distance (L-infinity distance) between two points in N-dimensional space. The result is the maximum of the absolute differences of their coordinates.
Syntax
chebyshevDistance(a | b)
Type Signatures
Array, Array
Parameters
NameTypeDescription
aArrayFirst point as an array of coordinates
bArraySecond point as an array of coordinates
Returns
number — The Chebyshev distance between points a and b
Examples
chebyshevDistance([0
0
convexHull
Computes the convex hull of a set of 2D points using Andrew\
Syntax
convexHull(points)
Parameters
NameTypeDescription
pointsArrayArray of 2D points [[x0,y0],[x1,y1],...]
Returns
Array — Array of 2D points forming the convex hull in CCW order
Examples
convexHull([[0
0
See Also
area distance
coordinateTransform
Transforms a point between coordinate systems. Supported systems: "cartesian", "polar", "spherical", "cylindrical". For polar: [r, theta]. For spherical (ISO): [r, theta, phi] where theta is the inclination and phi is the azimuth. For cylindrical: [rho, phi, z].
Syntax
coordinateTransform(point | from | to)
Type Signatures
Array, string, string
Parameters
NameTypeDescription
pointArrayThe point to transform
fromstringSource coordinate system
tostringTarget coordinate system
Returns
Array — The transformed point
Examples
coordinateTransform([1
0
See Also
distance
delaunayTriangulation
Computes the Delaunay triangulation of a set of 2D points using the Bowyer-Watson algorithm. Returns an array of triangles, each represented as three indices into the original points array.
Syntax
delaunayTriangulation(points)
Parameters
NameTypeDescription
pointsArrayArray of 2D points [[x0,y0],[x1,y1],...]
Returns
Array — Array of triangles [[i,j,k],...] with indices into points
Examples
delaunayTriangulation([[0
0
distance
Calculates the Euclidean distance between two points.
Syntax
distance([x1 | y1
Type Signatures
Array, Array, Array, Object, Object, Object, Array, Array, Object, Object
Parameters
NameTypeDescription
xArray | Matrix | ObjectCo-ordinates of first point
yArray | Matrix | ObjectCo-ordinates of second point
Returns
Number | BigNumber — Returns the distance from two/three points
Examples
distance([0
0
See Also
intersect
Computes the intersection point of lines and/or planes.
Syntax
intersect(expr1 | expr2 | expr3
Type Signatures
Matrix, Matrix, Matrix, Matrix, Matrix, Matrix, Matrix
Parameters
NameTypeDescription
wArray | MatrixCo-ordinates of first end-point of first line
xArray | MatrixCo-ordinates of second end-point of first line
yArray | MatrixCo-ordinates of first end-point of second line
zArray | MatrixCo-ordinates of second end-point of second line
Returns
Array — Returns the point of intersection of lines/lines-planes
Examples
intersect([0
0
See Also
kdTree
Builds a balanced k-d tree from an array of points for efficient nearest-neighbor and range queries. Returns an object with nearest(point, k) and rangeSearch(point, radius) methods.
Syntax
kdTree(points)
Parameters
NameTypeDescription
pointsArrayArray of 2D points [[x0,y0],[x1,y1],...]
Returns
Object — Object with nearest(point, k) and rangeSearch(point, radius)
Examples
kdTree([[0
0
manhattanDistance
Calculates the Manhattan distance (L1 distance) between two points in N-dimensional space. The result is the sum of the absolute differences of their coordinates.
Syntax
manhattanDistance(a | b)
Type Signatures
Array, Array
Parameters
NameTypeDescription
aArrayFirst point as an array of coordinates
bArraySecond point as an array of coordinates
Returns
number — The Manhattan distance between points a and b
Examples
manhattanDistance([0
0
minkowskiDistance
Calculates the Minkowski distance (Lp distance) between two points in N-dimensional space. Generalizes Euclidean (p=2), Manhattan (p=1), and Chebyshev (p=Infinity) distances.
Syntax
minkowskiDistance(a | b | p)
Type Signatures
Array, Array, number
Parameters
NameTypeDescription
aArrayFirst point as an array of coordinates
bArraySecond point as an array of coordinates
pnumberThe order of the Minkowski distance (p >= 1)
Returns
number — The Minkowski distance between points a and b
Examples
minkowskiDistance([0
0
pointInPolygon
Tests whether a 2D point lies inside a polygon using the ray casting algorithm. Returns true if the point is inside the polygon, false otherwise.
Syntax
pointInPolygon(point | polygon)
Type Signatures
Array, Array
Parameters
NameTypeDescription
pointArray2D point [x, y]
polygonArrayArray of 2D vertices [[x0,y0],[x1,y1],...]
Returns
boolean — true if point is inside the polygon
Examples
pointInPolygon([0.5
0.5
polygonPerimeter
Calculates the perimeter of a polygon by summing the Euclidean distances between consecutive vertices, including the closing edge from the last vertex back to the first.
Syntax
polygonPerimeter(vertices)
Parameters
NameTypeDescription
verticesArrayArray of 2D points [[x0,y0],[x1,y1],...]
Returns
number — The perimeter of the polygon
Examples
polygonPerimeter([[0
0
voronoiDiagram
Computes the Voronoi diagram of a set of 2D points as the dual of the Delaunay triangulation. Returns an object with vertices (circumcenters) and cells (ordered polygon vertex lists per input point).
Syntax
voronoiDiagram(points) | voronoiDiagram(points | bounds)
Type Signatures
Array, Array
Parameters
NameTypeDescription
pointsArrayArray of 2D points [[x0,y0],[x1,y1],...]
boundsArrayOptional bounding box [minX, minY, maxX, maxY]
Returns
Object — {vertices: number[][], cells: number[][][]}
Examples
voronoiDiagram([[0
0