Reference · Deterministic 2D physics
nearestTofunction
The nearest distance from a particle of a kind to a disc's surface (negative when it is inside), or Infinity when there is none.
Import it
import { nearestTo } from "@johnmorrisdotca/karakuri/physics";
Definition
function nearestTo(fluid: Fluid, kind: FluidKind, disc: Disc): number
Parameters
| Name | Type | Description |
|---|---|---|
fluid | Fluid | The mutable native particle fluid. |
kind | FluidKind | The native water, lava or stone particle kind. |
disc | Disc | The native disc whose surface distance is measured. |
Returns
number
The nearest surface gap for the requested particle kind, or Infinity when no such particle exists.
Examples
import { createFluid, fillRect, nearestTo } from "@johnmorrisdotca/karakuri/physics";
const fluid=createFluid({radius:2,gravity:0,iterations:1,reacts:false});
fillRect(fluid,"water",0,0,8,8);
console.log(nearestTo(fluid,"water",{x:0,y:0,r:1}));-0.1715728752538097What it prints (run when this page was built)