expandByPoint method
Implementation
Sphere expandByPoint(Vector3 point) {
// from https://github.com/juj/MathGeoLib/blob/2940b99b99cfe575dd45103ef20f4019dee15b54/src/Geometry/Sphere.cpp#L649-L671
_toPoint.subVectors(point, center);
var lengthSq = _toPoint.lengthSq();
if (lengthSq > (radius * radius)) {
var length = Math.sqrt(lengthSq);
var missingRadiusHalf = (length - radius) * 0.5;
// Nudge this sphere towards the target point. Add half the missing distance to radius,
// and the other half to position. This gives a tighter enclosure, instead of if
// the whole missing distance were just added to radius.
center.add(_toPoint.multiplyScalar(missingRadiusHalf / length));
radius += missingRadiusHalf;
}
return this;
}