3D Ray Triangle Intersection
Statement
Goal
When modeling 3D objects, it's often useful to be able to determine if a ray (point + vector) intersects a given triangle. Your job is to determine if there is a point on that triangular face where the ray intersects it, and print out its valueInput
Line 1-3 : T1, T2, and T3 comma-separated (x, y, z) coordinates of each vertex of the triangle
Line 4: O comma-separated (x, y, z) coordinates of the origin of the ray
Line 5: V comma-separated (x, y, z) components of the unit vector for the direction of the ray
Line 4: O comma-separated (x, y, z) coordinates of the origin of the ray
Line 5: V comma-separated (x, y, z) components of the unit vector for the direction of the ray
Output
The intersection point as comma-separated X, Y, Z coordinates, if the ray intersects the triangle, otherwise the words "NO INTERSECTION"
Constraints
The entire scenario (triangle, ray origin, and any potential intersection point) can fit within a bounding box -1000 ≤ {x, y, z} ≤ 1000
Example
Input
0,0,0 0,1,0 1,0,0 2,2,5 0,0,-1
Output
NO INTERSECTION
Game modes
Fastest, Shortest
Test cases
Test 1 Test
Input
0,0,0
0,1,0
1,0,0
2,2,5
0,0,-1
Output
NO INTERSECTION
Validator 1 Validator
Input
0,0,0
0,1,0
1,0,0
7,3,-4
0,0,1
Output
NO INTERSECTION
Test 2 Test
Input
0,0,0
0,4,0
4,0,0
2,2,5
0,0,-1
Output
2,2,0
Validator 2 Validator
Input
0,0,0
0,4,0
4,0,0
2,2,5
0,0,-1
Output
2,2,0
Test 3 Test
Input
0,0,0
10,1,0
0,1,10
4,12,4
0,-1,0
Output
4,0.8,4
Validator 3 Validator
Input
0,1,0
10,1,0
0,1,10
4,12,4
0,-1,0
Output
4,1,4
Test 4 Test
Input
0,10,0
10,1,0
0,1,10
4,12,4
0,-1,0
Output
4,2.8,4
Validator 4 Validator
Input
0,10,0
10,0,0
0,0,10
4,6,4
0,-1,0
Output
4,2,4
Solution language
Solution
Stub generator input