60 likes | 171 Views
Intersecting an A-A Cube. ?. 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.
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?