# How do I test if ray intersects segment? Of triangle?

Hi All-

I am trying to determine whether on not mesh facets intersect. I have extracted the facet data and tried to check if the segments intersect. (I already know that the facets are in the same plane)

I tried to check for intersection by creating a ray and testing it to see if it intersects a segment specified by 2 points:

If my understanding of the documentation is correct (and it probably isn’t)
BABYLON.Ray.CreateNewFromTo(p0,p1).intersectionSegment(p2,p3,100));
should return zero and it does not.

Any thoughts? Any ideas of alternate strategies?

Thanks and best to all!

Flex

It’s returning the distance from the origin to the intersection point, so it’s correct If it didn’t intersect it would return -1

1 Like

Ah, yes! So what you’re saying is that it behaves exactly like the docs say it does?

the distance from the ray origin to the intersection point if there’s intersection, or -1 if there’s no intersection

Oops , Thanks, Carol.