playcanvas
Version:
Open-source WebGL/WebGPU 3D engine for the web
66 lines (65 loc) • 3.1 kB
TypeScript
export namespace random {
/**
* Return a pseudo-random 2D point inside a unit circle with uniform distribution.
*
* @param {Vec2} point - The returned generated point.
* @example
* const point = new pc.Vec2();
* pc.random.circlePoint(point);
* // point now contains a random position inside a unit circle
*/
function circlePoint(point: Vec2): void;
/**
* Generates evenly distributed deterministic points inside a unit circle using Fermat's spiral
* and Vogel's method.
*
* @param {Vec2} point - The returned generated point.
* @param {number} index - Index of the point to generate, in the range from 0 to numPoints - 1.
* @param {number} numPoints - The total number of points of the set.
* @example
* const point = new pc.Vec2();
* for (let i = 0; i < 100; i++) {
* pc.random.circlePointDeterministic(point, i, 100);
* // point contains the i-th evenly distributed point in the circle
* }
*/
function circlePointDeterministic(point: Vec2, index: number, numPoints: number): void;
/**
* Generates evenly distributed deterministic points on a unit sphere using Fibonacci sphere
* algorithm. It also allows the points to cover only part of the sphere by specifying start
* and end parameters, representing value from 0 (top of the sphere) and 1 (bottom of the
* sphere). For example by specifying 0.4 and 0.6 and start and end, a band around the equator
* would be generated.
*
* @param {Vec3} point - The returned generated point.
* @param {number} index - Index of the point to generate, in the range from 0 to numPoints - 1.
* @param {number} numPoints - The total number of points of the set.
* @param {number} [start] - Part on the sphere along y axis to start the points, in the range
* of 0 and 1. Defaults to 0.
* @param {number} [end] - Part on the sphere along y axis to stop the points, in the range of
* 0 and 1. Defaults to 1.
* @example
* const point = new pc.Vec3();
* for (let i = 0; i < 100; i++) {
* pc.random.spherePointDeterministic(point, i, 100);
* // point contains the i-th evenly distributed point on the sphere
* }
*/
function spherePointDeterministic(point: Vec3, index: number, numPoints: number, start?: number, end?: number): void;
/**
* Generate a repeatable pseudo-random sequence using radical inverse. Based on
* http://holger.dammertz.org/stuff/notes_HammersleyOnHemisphere.html
*
* @param {number} i - The index in the sequence to return.
* @returns {number} The pseudo-random value.
* @example
* // Generate first 4 values of the sequence
* pc.random.radicalInverse(0); // returns 0
* pc.random.radicalInverse(1); // returns 0.5
* pc.random.radicalInverse(2); // returns 0.25
* pc.random.radicalInverse(3); // returns 0.75
*/
function radicalInverse(i: number): number;
}
import type { Vec2 } from './vec2.js';
import type { Vec3 } from './vec3.js';