union method

Sphere union(
  1. Sphere sphere
)

Implementation

Sphere union(Sphere sphere) {
  // from https://github.com/juj/MathGeoLib/blob/2940b99b99cfe575dd45103ef20f4019dee15b54/src/Geometry/Sphere.cpp#L759-L769

  // To enclose another sphere into this sphere, we only need to enclose two points:
  // 1) Enclose the farthest point on the other sphere into this sphere.
  // 2) Enclose the opposite point of the farthest point into this sphere.

  if (center.equals(sphere.center) == true) {
    _toFarthestPoint.set(0, 0, 1).multiplyScalar(sphere.radius);
  } else {
    _toFarthestPoint.subVectors(sphere.center, center).normalize().multiplyScalar(sphere.radius);
  }

  expandByPoint(_v1.copy(sphere.center).add(_toFarthestPoint));
  expandByPoint(_v1.copy(sphere.center).sub(_toFarthestPoint));

  return this;
}