I want to determine whether a point is within a 3D model, where the surface is represented by a series of triangles. Now, I use the ray method, which involves emitting a ray from that point and then calculating the set of intersection points between the ray and all triangles. If the number of intersection points is odd, then the points are within the model. However, during the application process, a problem was found. Sometimes the rays intersect with the edges or vertices of the triangles. If the rays intersect the edge of a triangle, two identical intersection points will be generated. If the rays intersect at the vertex of a triangle, multiple identical intersection points will be generated (depending on how many triangular faces share the vertex). And then I do not know how to count the intersection number now. For example, judge point A, I can get intersection point B and C. But C is the vertex of triangles, so I may get many serial same point C from serial triangles. How to count the intersection number now?

A simpler way is to change the direction of the ray, but I need to judge multiple points and they lie in one line. So, I just need to generate the ray which direction is along the line. In other word, I do not want to change the direction of the way.