Graphics Reference
In-Depth Information
// Compute the squared distances for the three pairs of points
float dist2x = Dot(pt[maxx] - pt[minx], pt[maxx] - pt[minx]);
float dist2y = Dot(pt[maxy] - pt[miny], pt[maxy] - pt[miny]);
float dist2z = Dot(pt[maxz] - pt[minz], pt[maxz] - pt[minz]);
// Pick the pair (min,max) of points most distant
min = minx;
max = maxx;
if (dist2y > dist2x && dist2y > dist2z) {
max = maxy;
min = miny;
}
if (dist2z > dist2x && dist2z > dist2y) {
max = maxz;
min = minz;
}
}
void SphereFromDistantPoints(Sphere &s, Point pt[], int numPts)
{
// Find the most separated point pair defining the encompassing AABB
int min, max;
MostSeparatedPointsOnAABB(min, max, pt, numPts);
// Set up sphere to just encompass these two points
s.c = (pt[min] + pt[max]) * 0.5f;
s.r = Dot(pt[max] - s.c, pt[max] - s.c);
s.r = Sqrt(s.r);
}
In the second pass, all points are looped through again. For all points outside the
current sphere, the sphere is updated to be the sphere just encompassing the old
sphere and the outside point. In other words, the new sphere diameter spans from
the outside point to the point on the backside of the old sphere opposite the outside
point, with respect to the old sphere center.
// Given Sphere s and Point p, update s (if needed) to just encompass p
void SphereOfSphereAndPt(Sphere &s, Point &p)
{
// Compute squared distance between point and sphere center
Vectord=p-s.c;
float dist2 = Dot(d, d);
// Only update s if point p is outside it
 
Search WWH ::




Custom Search