setFromCartesianCoords method

Spherical setFromCartesianCoords(
  1. double x,
  2. double y,
  3. double z
)

Sets values of this spherical's radius, phi and theta properties from Cartesian coordinates.

Implementation

Spherical setFromCartesianCoords(double x, double y, double z) {
  radius = math.sqrt(x * x + y * y + z * z);

  if (radius == 0) {
    theta = 0;
    phi = 0;
  } else {
    theta = math.atan2(x, z);
    phi = math.acos(MathUtils.clamp(y / radius, -1, 1));
  }

  return this;
}