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

closestOnSegmentfunction

The point on the segment a to b nearest to (px, py), and how far along the segment it is (0 to 1).

Import it

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

Definition

function closestOnSegment(px: number, py: number, ax: number, ay: number, bx: number, by: number): { x: number; y: number; t: number; }

Parameters

NameTypeDescription
pxnumber

The horizontal coordinate of the point to test.

pynumber

The vertical coordinate of the point to test.

axnumber

The first segment endpoint’s horizontal coordinate.

aynumber

The first segment endpoint’s vertical coordinate.

bxnumber

The second segment endpoint’s horizontal coordinate.

bynumber

The second segment endpoint’s vertical coordinate.

Returns

{ x: number; y: number; t: number; }

The point on the segment a to b nearest to (px, py), and how far along the segment it is (0 to 1).

Examples

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

console.log(closestOnSegment(3,4,0,0,10,0));
{ x: 3, y: 0, t: 0.3 }

What it prints (run when this page was built)

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