Exercise from Last year Exam

Question 16 ( 8 marks ) :

Write an algorithm (Java-like pseudocode) that will calculate the point of intersection of a ray (semi segment) and a triangle. The method should return the status of the intersection (intersect or not, and, if not, why not ). If it intersects, then the method should also return the coordinates of the intersection. Use comments in your code to explain the algorithm.

The ray is defined by the origin point O and the direction vector V.
The triangle is defined by the 3 vertices P0, P1, P2.

Tip : if vertices A, B, C and D are on the same plane and if D = A + sAB + tAC then D is inside triangle ABC if and only if s>=0, t>=0 and s+t <= 1

Next Week...