本文へ移動

Karakuriからくり

8つの標準のパズルで遊び、探索や再現できる物理を使い、ポインターやキーボードで操作する盤を表示できます。

「からくり」は、仕組みや工夫した装置を表す言葉です。 名前について(英語)

目次

リファレンス · 再現できる2D物理

closestOnSegment関数

リファレンスの説明と例は英語です。見出しと目次は日本語です。

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

インポート

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

定義

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

引数

名前型説明
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.

戻り値

{ 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).

例

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

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

出力(このページを作ったときに実行した結果)

ソースを見るGitHub で編集@johnmorrisdotca/karakuri 0.2.1 のソースから作成しました。

この日本語は、まだ日本語を母語とする方の確認を受けていません。訂正を歓迎します。