UNPKG

@fimbul-works/vec

Version:

A comprehensive TypeScript vector math library providing 2D, 3D, and 4D vector operations with a focus on performance and type safety.

10 lines (9 loc) 342 B
/** * Creates a random unit 2D vector. * @param {() => void} random - A function that returns a random number between 0 and 1 (default: `Math.random`) * @returns {ArrayVector2D} Random unit vector */ export const random2D = (random = Math.random) => { const phi = random() * Math.PI * 2; return [Math.cos(phi), Math.sin(phi)]; };