StaticcrossStaticdotStaticfixFixes floating-point calculation errors by converting very small numbers to zero.
Number to fix
Fixed number (0 if smaller than epsilon, otherwise unchanged)
StaticgetReturns the closest point on an edge segment to the given point.
Point to project. Should have properties x and y.
Edge to project onto, defined by two endpoints point1 and point2.
Each endpoint should have properties x and y.
Projected point on the edge, with x and y coordinates.
StaticgetCalculates the normal vector of a line segment.
X coordinate of the first point
X coordinate of the second point
Y coordinate of the first point
Y coordinate of the second point
A normalized Vector representing the line's normal
StaticgetCreates a unit vector from an angle in radians.
Angle in radians
A normalized Vector pointing in the direction of the angle
StaticisDetermines if a point is inside a polygon.
The point to test. Should have properties x and y.
An array of edges representing the polygon.
Each edge is defined by two endpoints point1 and point2,
where each endpoint has properties x and y.
Returns true if the point is inside the polygon, otherwise false.
The algorithm may be inaccurate in edge cases, such as when the point lies exactly on a polygon corner.
const point = { x: 5, y: 5 };
const polygon = [
{ point1: { x: 2, y: 12 }, point2: { x: 12, y: 12 } },
{ point1: { x: 12, y: 12 }, point2: { x: 12, y: 2 } },
{ point1: { x: 12, y: 2 }, point2: { x: 2, y: 2 } },
{ point1: { x: 2, y: 2 }, point2: { x: 2, y: 12 } },
];
const isInside = VectorOps.isPointInPolygon(point, polygon);
Staticrotate
Utility class providing static methods for vector operations and geometric calculations.
This class contains mathematical operations for working with 2D vectors, points, and geometric shapes. All methods are static and can be used without instantiating the class.
Example