# Raytracing

This topic is 1688 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm not quite sure which section this question be better suited, so feel free to move it.

This question is about raytracing line-triangle, more specifically, a vertical line intersecting with a triangle.

I'm following the algorithm from http://www.angelfire.com/fl/houseofbartlett/solutions/line2tri.html#Code

Goal: Place a vertical line anywhere on a non-flat surface(terrain) and be able to detect which triangle it hits.

I'll try to make my question simple:

When my line point starts above the terrain and has a negative vertical vector direction(enough to pierce the terrain and create intersection), I produce correct results:

//vertical line from 10y to -10y
vec3f linept = {0.0, 10.0, 0.0}; //start line point
vec3f linevect = {0.0, -20.0, 0.0}; // line vector direction


*the black triangle means the line-triangle algorithm has returned true for that polygon.

While simply having the line start below the terrain, instead of the top, and changing the direction of the line direction(from down->top), which you would think have no effect and still pierce the terrain because it's really still the same line, now does not recognize intersecting with the triangle:

//vertical line from -10y to 10y
vec3f linept = {0.0, -10.0, 0.0}; //start line point
vec3f linevect = {0.0, 20.0, 0.0}; // line vector direction


*the algorithm does not deal with normalized vectors of direction, so that's why the line's direction is (0,10,0) instead of (0,1,0).

Why does changing the vector direction make the algorithm fail?

Edited by Shawn619

##### Share on other sites

The dot product between the normal of the surface and your intersection vector will be > 0 and thus fail the if test in the intersection test.

This means that the intersection test is designed to use back-face culling, i.e. the back of a triangles are not visible.

##### Share on other sites

Ah, that wasn't mentioned in the algorithm notes. Thanks!