setFromPoints method
Computes the minimum bounding sphere for list of points. If the optional center point is given, it is used as the sphere's center. Otherwise, the center of the axis-aligned bounding box encompassing the points is calculated.
points
- A list of points in 3D space.
optionalCenter
- The center of the sphere.
return A reference to this sphere.
Implementation
BoundingSphere setFromPoints(List<Vector3> points, [Vector3? optionalCenter ]) {
final center = this.center;
if ( optionalCenter != null ) {
center.setFrom( optionalCenter );
}
else {
_box.setFromPoints(points).getCenter(center);
}
double maxRadiusSq = 0;
for (int i = 0, il = points.length; i < il; i ++ ) {
maxRadiusSq = math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );
}
this.radius = math.sqrt( maxRadiusSq );
return this;
}