我有一个由中心点和半径在对象空间中表示的球体。球体通过一个可能包括缩放、旋转和平移的变换矩阵被变换到世界空间。我需要为世界空间中的球体构建一个轴对齐的边界框,但我不知道该怎么做。
这是我目前的方法,适用于某些情况:
public void computeBoundingBox() {
// center is the middle of the sphere
// averagePosition is the middle of the AABB
// getObjToWorldTransform() is a matrix from obj to world space
getObjToWorldTransform().rightMultiply(center, averagePosition);
Point3 onSphere = new Point3(center);
onSphere.scaleAdd(radius, new Vector3(1, 1, 1));
getObjToWorldTransform().rightMultiply(onSphere);
// but how do you know that the transformed radius is uniform?
double transformedRadius = onSphere.distance(averagePosition);
// maxBound is the upper limit of the AABB
maxBound.set(averagePosition);
maxBound.scaleAdd(transformedRadius, new Vector3(1, 1, 1));
// minBound is the lower limit of the AABB
minBound.set(averagePosition);
minBound.scaleAdd(transformedRadius, new Vector3(-1,-1,-1));
}
但是,我怀疑这是否总是有效。它不应该因非均匀缩放而失败吗?