Here's a constructor to construct a axis-aligned bounding box given two opposite vertices on the bounding box, from Pharr's Physically Based Rendering, Third Edition.
BBox(const Point &p1, const Point &p2) {
pMin = Point(min(p1.x, p2.x), min(p1.y, p2.y), min(p1.z, p2.z));
pMax = Point(max(p1.x, p2.x), max(p1.y, p2.y), max(p1.z, p2.z));
}
I don't understand why this works; for example if I take $P_1 = (1,2,3)$ and $P_2 = (2,1,4)$, I'll get $\text{pMin} = (1,1,3)$ and $\text{pMax} = (2,2,4)$. The bounding box between $P_1$ and $P_2$ is doesn't look same as bounding box between pMin
and pMax
.
The explanation for this constructor given in the book :
If the caller passes two corner points (
p1
andp2
) to define the box, sincep1
andp2
are not necessarily chosen so thatp1.x
<=p2.x
, and so on, the constructor needs to find their component-wise minimum and maximum values.
As far as I understand, if p1.x
is less than p2.x
then pMin = p1
. So we should only be checking against p1.x
and p2.x
.
Am I missing something ? The above constructor doesn't feel correct for axis-aligned bounding boxes.