function CameraUtils.getLooseBoundingSphere(t)local y=table.create(#t)for t,S in pairs(t)do y[t]=S.Position end local S=y[1]local g=S local W=0 for t,y in ipairs(y)do local R=(y-S).Magnitude if R>W then g=y W=R end end local R=g local e=0 for t,y in ipairs(y)do local S=(y-g).Magnitude if S>e then R=y e=S end end local Z=(g+R)*.5 local A=(g-R).Magnitude*.5 for t,y in ipairs(y)do local S=(y-Z).Magnitude if S>A then Z=Z+((S-A)*.5)*(y-Z).Unit A=(S+A)*.5 end end return Z,A end
-- Ritter's loose bounding sphere algorithm
function CameraUtils.getLooseBoundingSphere(parts)
	local points = table.create(#parts)
	for idx, part in pairs(parts) do
		points[idx] = part.Position
	end

	-- pick an arbitrary starting point
	local x = points[1]

	-- get y, the point furthest from x
	local y = x
	local yDist = 0

	for _, p in ipairs(points) do
		local pDist = (p - x).Magnitude

		if pDist > yDist then
			y = p
			yDist = pDist
		end
	end

	-- get z, the point furthest from y
	local z = y
	local zDist = 0

	for _, p in ipairs(points) do
		local pDist = (p - y).Magnitude

		if pDist > zDist then
			z = p
			zDist = pDist
		end
	end

	-- use (y, z) as the initial bounding sphere
	local sc = (y + z) * 0.5
	local sr = (y - z).Magnitude * 0.5

	-- expand sphere to fit any outlying points
	for _, p in ipairs(points) do
		local pDist = (p - sc).Magnitude

		if pDist > sr then
			-- shift to midpoint
			sc = sc + (pDist - sr) * 0.5 * (p - sc).Unit

			-- expand
			sr = (pDist + sr) * 0.5
		end
	end

	return sc, sr
end
