math.vec3.dist¶
Summary¶
math.vec3.dist computes the Euclidean distance between two 3D vectors in their coordinate units.
Use distsq instead when only relative distance comparisons are needed and the square root can be avoided.
Syntax¶
WasmGPU.math.vec3.dist(v1: number[], v2: number[]): number
const result = wgpu.math.vec3.dist(v1, v2);
Precision-Specific Wasm Forms¶
WasmGPU.math.vec3f.dist(a: WasmPtr, b: WasmPtr): number
WasmGPU.math.vec3d.dist(a: WasmPtr, b: WasmPtr): number
These forms use caller-owned pointers to 3-element vector blocks in WasmGPU driver memory: binary32 for vec3f and binary64 for vec3d. Methods with an output pointer write that block instead of allocating a JavaScript array. See WasmGPU.math for allocation, views, aliasing, and release requirements.
Parameters¶
| Name | Type | Required | Description |
|---|---|---|---|
v1 |
number[] |
Yes | First vector input as [x, y, z]. |
v2 |
number[] |
Yes | Second vector input as [x, y, z]. |
Returns¶
number - Euclidean distance between the two inputs.
Type Details¶
Example¶
const canvas = document.querySelector("canvas");
const wgpu = await WasmGPU.create(canvas);
const v1 = [1, -1, 0.5];
const v2 = [0, 1, 0];
const result = wgpu.math.vec3.dist(v1, v2);
console.log(result);