This repository contains a collection of TypeScript utility functions for geometric calculations, primarily focused on line intersection and distance calculations.
- Line intersection detection
- Segment intersection detection
- Point-to-segment distance calculation
- Orientation of points
- Distance between points
bun add @tscircuit/math-utils
Import the functions you need in your TypeScript project:
import {
doesLineIntersectLine,
doSegmentsIntersect,
pointToSegmentDistance,
} from "./src/index"
// Example usage
const point1 = { x: 0, y: 0 }
const point2 = { x: 5, y: 5 }
const point3 = { x: 0, y: 5 }
const point4 = { x: 5, y: 0 }
const intersects = doesLineIntersectLine([point1, point2], [point3, point4])
console.log("Lines intersect:", intersects)
doesLineIntersectLine(line1: [Point, Point], line2: [Point, Point], options?: { lineThickness?: number }): boolean
Determines if two lines intersect, optionally considering line thickness.
Checks if two line segments intersect.
Calculates the orientation of three points.
Checks if point q lies on the segment p-r.
Calculates the minimum distance between a point and a line segment.
Calculates the Euclidean distance between two points.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is open source and available under the MIT License.