-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4bee1fe
commit 56eebca
Showing
2 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,55 @@ | ||
/** | ||
* Returns a random value -1 or 1 | ||
* | ||
* @see {@link https://pt.wikipedia.org/wiki/Passeio_aleat%C3%B3rio} | ||
* | ||
* @returns {number[]} | ||
*/ | ||
export function randomWalk1D() { | ||
return [Math.random() < 0.5 ? -1 : 1]; | ||
} | ||
|
||
/** | ||
* Return a changed random axis (x or y) | ||
* | ||
* @see {@link https://pt.wikipedia.org/wiki/Passeio_aleat%C3%B3rio} | ||
* | ||
* @returns {number[]} | ||
*/ | ||
export function randomWalk2D() { | ||
if (Math.random() < 0.5) return [...randomWalk1D(), 0]; | ||
else return [0, ...randomWalk1D()]; | ||
} | ||
|
||
/** | ||
* Return a changed random axis (x, y or z) | ||
* | ||
* @see {@link https://pt.wikipedia.org/wiki/Passeio_aleat%C3%B3rio} | ||
* | ||
* @returns {number[]} | ||
*/ | ||
export function randomWalk3D() { | ||
const rdn = Math.random(); | ||
if (rdn < 0.333) return [...randomWalk1D(), 0, 0]; | ||
if (rdn < 0.666) return [0, ...randomWalk1D(), 0]; | ||
else return [0, 0, ...randomWalk1D()]; | ||
} | ||
|
||
|
||
// TODO: Update this function | ||
export function randomWalk( | ||
numberOfAxes = 2, | ||
trend = { | ||
left: 0.25, right: 0.25, | ||
up: 0.25, down: 0.25, | ||
front: 0, backward: 0, | ||
}, | ||
bounds = { | ||
x: { min: -Infinity, max: Infinity, }, | ||
y: { min: -Infinity, max: Infinity, }, | ||
z: { min: -Infinity, max: Infinity, }, | ||
}) { | ||
if (numberOfAxes = 1) { | ||
|
||
} | ||
} |