60 likes | 180 Views
This document explores the algorithm for detecting intersections between a ray and an Axis-Aligned Cube (AAC) in 3D space. It covers the calculation of intersection points, handling up to three intersections, and differentiating between inside-to-outside and outside-to-inside intersections. The algorithm uses ray parameters to determine intersections, storing results in respective arrays. Key conditions manage parallel rays and edge cases for when rays originate inside the cube. This detailed approach ensures accurate detection and processing of ray intersections in graphical applications.
E N D
? Axis-Aligned Cube x,y = +/- 0.5
Axis-Aligned Cube float s[3],d[3]; // R(t) = s + t*d float toutin[3],tinout[3]; // hold 3 intersections (t values) Int inout,outin; // indices into t arrays
Axis-Aligned Cube For each boundary plane inout = outin = 0; if (fabs(d[0]) > epsilon) { t = (-0.5 - s[0])/d[0]; if (s[0]<-0.5) toutin[outin++] = t; else tinout[inout++] = t; } else { // ray parallel to plane if (s[0] < -0.5) <no intersection at all> else <ignore this limit> }
Axis-Aligned Cube in 3D, up to 3 intersections tinout[3] toutin[3] // find largest out-to-in, smallest in-to-out toi = toutin[0]; If ((outin==2)&&(toutin[1] > toi)) toi = toutin[1]; Tio = tinout[0]; If ((inout==2)&&(tinout[1] > tio)) tio = tinout[1]; If (toi < tio) t = toi;
Axis-Aligned Cube If start inside, need first in-to-out intersection With this code, how do you tell if you started inside?