MCPcopy Index your code
hub / github.com/mrdoob/three.js / randomDirection

Method randomDirection

src/math/Vector3.js:1234–1248  ·  view source on GitHub ↗

* Sets this vector to a uniformly random point on a unit sphere. * * @return {Vector3} A reference to this vector.

()

Source from the content-addressed store, hash-verified

1232 * @return {Vector3} A reference to this vector.
1233 */
1234 randomDirection() {
1235
1236 // https://mathworld.wolfram.com/SpherePointPicking.html
1237
1238 const theta = Math.random() * Math.PI * 2;
1239 const u = Math.random() * 2 - 1;
1240 const c = Math.sqrt( 1 - u * u );
1241
1242 this.x = c * Math.cos( theta );
1243 this.y = u;
1244 this.z = c * Math.sin( theta );
1245
1246 return this;
1247
1248 }
1249
1250 *[ Symbol.iterator ]() {
1251

Callers 1

Vector3.tests.jsFile · 0.80

Calls 1

randomMethod · 0.45

Tested by

no test coverage detected