I am trying to find the quickest way to compue the bbox of a partial
sphere where the coordinate of the sphere are defined as usual
pts->x = radius * cosf(theta) * cosf(phi);
pts->y = radius * sinf(theta) * cosf(phi);
pts->z = radius * sinf(theta);
what I mean by partial is that the sphere can be defined by a theta
min and a theta max and a phi min and a phi max such that it possible
to represent only portions of a complete sphere. So I am trying to
compute the bbox of these 'bits' of sphere. It seems pretty simple for
z (compute the value for thetamin & thetamax) but what's the best way
of compute the min & max values for x & y depending on thetamin
thetamax and phimin and phimax ?
Any idea ?
thanks a lot -coralie
Hi Coralie,
I haven't implemented this algorithm myself. However, here's the
analysis I've carried out this far and it works at least in my mind:)
Let us concentrate on finding the minimum x component with a radius 1
(without loss of generality). It is a function of two variables theta
and phi:
x(theta, phi) = cos(theta) cos(phi)
Visualize this function on the domain D = [0, 2pi] x [-pi / 2, pi / 2].
You'll see it looks like a valley. Outside D the function repeats itself
using this basic block.
Convince yourself on that it is equivalent to consider:
1) Finding a minimum of x on an arbitrary rectangular box on R^2.
2) Finding a minimum of x on at most two rectangular boxes on D, when
these boxes have been chosen properly.
Therefore, the problem is reduced to:
* Find an algorithm to chop an arbitrary rectangular box to two
appropriate boxes on D. Not hard.
* Find an algorithm to find a minimum on a single rectangular box on D.
* The solution is a minimum of the minima of the (at most) two boxes.
About the latter algorithm:
x has one minimum (with value -1) at the center of D. If the box
contains this center, then min x = -1. Otherwise the minimum is
contained on some edge of the box.
What do you think? How's your renderer progressing?:)
Well, you possibly need more, 4 must be enough. Anyway, the same idea
holds.