Reference · Deterministic 2D physics
segmentsIntersectfunction
Whether the segments a1 to a2 and b1 to b2 cross or touch.
Import it
import { segmentsIntersect } from "@johnmorrisdotca/karakuri/physics";
Definition
function segmentsIntersect(a1x: number, a1y: number, a2x: number, a2y: number, b1x: number, b1y: number, b2x: number, b2y: number): boolean
Parameters
| Name | Type | Description |
|---|---|---|
a1x | number | The first segment’s starting horizontal coordinate. |
a1y | number | The first segment’s starting vertical coordinate. |
a2x | number | The first segment’s ending horizontal coordinate. |
a2y | number | The first segment’s ending vertical coordinate. |
b1x | number | The other segment’s starting horizontal coordinate. |
b1y | number | The other segment’s starting vertical coordinate. |
b2x | number | The other segment’s ending horizontal coordinate. |
b2y | number | The other segment’s ending vertical coordinate. |
Returns
boolean
Whether the segments a1 to a2 and b1 to b2 cross or touch.
Examples
import { segmentsIntersect } from "@johnmorrisdotca/karakuri/physics";
console.log(segmentsIntersect(0,0,10,10,0,10,10,0));trueWhat it prints (run when this page was built)