Skip to the content

Karakuriからくり

Play eight native puzzles, run bounded searches, step deterministic physics and mount a canvas player controlled by pointer or keyboard.

Karakuri is the Japanese word からくり for a mechanism or ingenious device. About the name

Contents

Reference · Deterministic 2D physics

closestBetweenSegmentsfunction

The nearest points of two segments: where on each, and how far apart they are. Crossing segments are 0 apart.

Import it

import { closestBetweenSegments } from "@johnmorrisdotca/karakuri/physics";

Definition

function closestBetweenSegments(a1x: number, a1y: number, a2x: number, a2y: number, b1x: number, b1y: number, b2x: number, b2y: number): { ax: number; ay: number; bx: number; by: number; distance: number; }

Parameters

NameTypeDescription
a1xnumber

The first segment’s starting horizontal coordinate.

a1ynumber

The first segment’s starting vertical coordinate.

a2xnumber

The first segment’s ending horizontal coordinate.

a2ynumber

The first segment’s ending vertical coordinate.

b1xnumber

The other segment’s starting horizontal coordinate.

b1ynumber

The other segment’s starting vertical coordinate.

b2xnumber

The other segment’s ending horizontal coordinate.

b2ynumber

The other segment’s ending vertical coordinate.

Returns

{ ax: number; ay: number; bx: number; by: number; distance: number; }

The nearest points of two segments: where on each, and how far apart they are. Crossing segments are 0 apart.

Examples

import { closestBetweenSegments } from "@johnmorrisdotca/karakuri/physics";

console.log(closestBetweenSegments(0,0,10,0,0,5,10,5));
{ ax: 0, ay: 0, bx: 0, by: 5, distance: 5 }

What it prints (run when this page was built)

View sourceEdit on GitHubMade from the source of @johnmorrisdotca/karakuri 0.2.1.