Main
Vectors
Matrix
Matrix Manipulation
Transformation Matrices
Angles
Random
Bezier Curve
Equations
Path Movement
Color
Linear Interpolation
Derivatives
Collision Detection
Animation
Circle And Ellipse
Sequence
Combinatorics
Other

Convex Polygons Collision

This function convexPolygonsCollide() returns true if the convex polygons collide. It implements Separating Axis Theorem (SAT).

import { convexPolygonsCollide } from 'mz-math';

const poly1: Vector2[] = [[0, 0], [10, 0], [5, 10]];
const poly2: Vector2[] = [[5, 5], [15, 5], [10, 15]];

const isCollide = convexPolygonsCollide(poly1, poly2); // true

IPolygon type is defined as follows:

export type IPolygon = Vector2[];