randomDirection method

Vector3 randomDirection()

Implementation

Vector3 randomDirection() {
  // Derived from https://mathworld.wolfram.com/SpherePointPicking.html

  var u = (Math.random() - 0.5) * 2;
  var t = Math.random() * Math.pi * 2;
  var f = Math.sqrt(1 - u * u);

  x = f * Math.cos(t);
  y = f * Math.sin(t);
  z = u;

  return this;
}