achhabra@uceng.UC.EDU (atul k chhabra) (04/12/89)
I have a question about checking for ray/bounding box intersection in ray
tracing. Rogers ("Procedural Elements for Computer Graphics," 1985,
pp. 299) suggests a transformation comprising of translation and rotations
about the coordinate axes, in order to make the ray coincident with the
z-axis. This transformation is applied to both the ray and the bounding
box. Rogers goes on to say that the ray intersects the box if, in the
translated and rotated coordinate system, the signs of x_min and x_max
AND of y_min and y_max are opposite. He illustrates this with a ray-box
configuration which, after aligning the ray with the z-axis, looks as
shown below.
^ y
|
|
------|------
| | |
| | | x
----------------------->
| | |
| | | (z-axis perpendicular to the screen)
------|------
|
|
But what if the transformation leads to a configuration as shown below?
In this case, you cannot infer anything about the ray/bounding box
intersection from the values of x_min, x_max, y_min, and y_max.
x_min and x_max have opposite signs. Also, y_min and y_max have opposite
signs. Yet the ray (z-axis) does not intersect the bounding box (cube).
^
| y
| ------------------
| / / \
| / / \ x
-----|---/----------------/---------\------>
| / / \
| / \
/ | / \
---|--------------
\ | \ /
| \ /
| \ \ /
| \ \ /
| \ \ /
\ \ /
------------------
(z-axis perpendicular to the screen)
(Say, a unit cube first translated, then rotated about
the x-axis and next rotated about the y-axis, such that
the same transformation makes the ray lie on the z-axis).
Could some ray tracing guru clarify this? Am I using the right kind of
transformations? In addition to determining whether the ray intersects the
bounding box, I am also interested in computing the coordinates of the
point of intersection closest to the origin of the ray. Could some kind soul
email me a piece of code that does the computations for ray/bounding box
intersection?
Thanks,
Atul
---------------------------------------------------------------------------
Atul K. Chhabra INTERNET: achhabra@ucesp1.ece.uc.edu
811J Rhodes Hall, ML 030 (129.137.33.114)
Dept. of Electrical & OR achhabra@uceng.uc.edu
Computer Engineering (129.137.33.1)
University of Cincinnati
Cincinnati, OH 45221-0030 Phone: (513)556-4766
---------------------------------------------------------------------------spencer@eecs.umich.edu (Spencer W. Thomas) (04/12/89)
In article <857@uceng.UC.EDU> achhabra@uceng.UC.EDU (atul k chhabra) writes: > I have a question about checking for ray/bounding box intersection in ray > tracing. Rogers ("Procedural Elements for Computer Graphics," 1985, > pp. 299) suggests a transformation comprising of translation and rotations > about the coordinate axes, in order to make the ray coincident with the > z-axis. [Points out problem: some bounding boxes pass this test, but are not intersected by the ray.] I think the point here is to make a cheap test. What he is really doing is testing against the bounding box of the transformed bounding box (call it TB). Any intersection with the original box (call it B) is guaranteed to intersect TB, but there are ray intersections with TB that don't intersect B. This is not a problem, except that it can make you do more ray-object tests than you would have with a better ray-box test. So, the question is, do you lose worse by doing a few more ray-object intersections or by having a more expensive ray-box test (which will presumably occur much more frequently than the r-o test)? If you are really worried about it, you can do the (more expensive) test of the original ray against the original box (this involves intersecting the ray with each bounding plane -- if any of these intersections falls inside the corresponding face bounds, then the ray intersects the box) after the cheap test has succeeded. However, you'd probably do better by using Kay-Kajiya bounding "boxes" instead. (See paper in SIGGRAPH 1986 proceedings.) -- =Spencer (spencer@eecs.umich.edu)