Reference · Deterministic 2D physics
distanceToSegmentfunction
How far (px, py) is from the segment a to b.
Import it
import { distanceToSegment } from "@johnmorrisdotca/karakuri/physics";
Definition
function distanceToSegment(px: number, py: number, ax: number, ay: number, bx: number, by: number): number
Parameters
| Name | Type | Description |
|---|---|---|
px | number | The horizontal coordinate of the point to test. |
py | number | The vertical coordinate of the point to test. |
ax | number | The first segment endpoint’s horizontal coordinate. |
ay | number | The first segment endpoint’s vertical coordinate. |
bx | number | The second segment endpoint’s horizontal coordinate. |
by | number | The second segment endpoint’s vertical coordinate. |
Returns
number
How far (px, py) is from the segment a to b.
Examples
import { distanceToSegment } from "@johnmorrisdotca/karakuri/physics";
console.log(distanceToSegment(3,4,0,0,10,0));4What it prints (run when this page was built)