IntersectRayTri(o,d,p<sub>0</sub>,p<sub>1</sub>,p<sub>2</sub>) returns ({REJECT, INTERSECT},u,v,t); 1: e1=p<sub>1</sub>-p<sub>0</sub> 2: e2=p<sub>2</sub>-p<sub>0</sub> 3: r=d × e<sub>2</sub> 4: a=e<sub>1</sub> <img src="http://twimgs.com/ddj/ddj/images/ddj0008b/dot12.gif" width="6" height="9" align="baseline"> r 5: s=o-p<sub>0</sub> 6: f=1/a 7: q=s × e<sub>1</sub> 8: if (a><img src="http://twimgs.com/ddj/ddj/images/ddj0008b/e12.gif" width="7" height="9">) 9: { 10: u=s <img src="http://twimgs.com/ddj/ddj/images/ddj0008b/dot12.gif" width="6" height="9" align="baseline"> r 11: if (u<0.0 or u>a) return (REJECT,0,0,0); 12: v= d <img src="http://twimgs.com/ddj/ddj/images/ddj0008b/dot12.gif" width="6" height="9" align="baseline"> q 13: if (v<0.0 or u+v>a) return (REJECT,0,0,0); 14: } 15: else if (a < -<img src="http://twimgs.com/ddj/ddj/images/ddj0008b/e12.gif" width="7" height="9">) 16: { 17: u= s <img src="http://twimgs.com/ddj/ddj/images/ddj0008b/dot12.gif" width="6" height="9" align="baseline"> r 18: if (u>0.0 or u<a) return (REJECT,0,0,0); 19: v= d <img src="http://twimgs.com/ddj/ddj/images/ddj0008b/dot12.gif" width="6" height="9" align="baseline"> q 20: if (v>0.0 or u+v<a) return (REJECT,0,0,0); 21: } 22: else return (REJECT,0,0,0); 23: t=<i></i> *(e<sub>2</sub> <img src="http://twimgs.com/ddj/ddj/images/ddj0008b/dot12.gif" width="6" height="9" align="baseline"> q) 24: u=u * ; 25: v=v * ; 26: return (INTERSECT,u,v,t);
Example 5: Checking front- and back-facing triangles.