I’m trying to figure out why a script I wrote that uses intersect_ray_tri isn’t yielding the results I expect. Here is a little code to reproduce the issue:
import mathutils # a triangle "overhead"... +z being up v1 = mathutils.Vector((0, 1, 1)) v2 = mathutils.Vector((1, -1, 1)) v3 = mathutils.Vector((-1, -1, 1)) origin = mathutils.Vector((0, 0, 0)) # makes sense that this should report an intersection, since it's going up through the triangle ray = mathutils.Vector((0, 0, 2)) print(mathutils.geometry.intersect_ray_tri(v1, v2, v3, ray, origin)) # but why does this report an intersection? ray = mathutils.Vector((0, 0, -2)) print(mathutils.geometry.intersect_ray_tri(v1, v2, v3, ray, origin))
This is using blender’s coordinate system of z = up, x = right, y = out. The triangle composed of v1, v2, and v3 is “overhead”, and the first intersection test is a ray shooting straight up through it. However, the second test is a ray going the complete opposite direction, yet it also has an intersection.
It seems that intersect_ray_tri is treating the ray as an infinite line… the magnitude of the ray doesn’t seem to matter, and neither does the direction (one way or the opposite way).
Can anybody shed some light on this? Thanks