e 122 Report post Posted July 22, 2000 Can anyone please me how to test if a ray and a triangle (or any kind of convex polygon) intersect. Thanks. -e 0 Share this post Link to post Share on other sites

rowbot 122 Report post Posted July 22, 2000 First get the point of intersection between the ray and the plane of the polygon. You can do this by substituting the paramtric equations for x,y and z of the ray into the plane equation and then solving for t.Then you have to check if that point is inside all of the edges of the polygon. One way is to create planes though each of the edges and perpendicular to the polygon plane. If a point on the polygon is on the opposite side of that plane to the intersection point then they ray does not intersect it.I''d give you code and equations but I havent got them on me at the moment. Try searching these forums or the web.ro 0 Share this post Link to post Share on other sites

Nate 122 Report post Posted July 22, 2000 Check out this page, http://www.swin.edu.au/astronomy/pbourke/geometry/, there is some good info there. Also, I put the code that I have been using for ray triangle intersection here, http://nate.scuzzy.net/common/. The files you should look at are util3d.cpp and util3d.h. Hope this helps. Nate Millerhttp://nate.scuzzy.net 0 Share this post Link to post Share on other sites

Guest Anonymous Poster Report post Posted July 22, 2000 I have a similar problem.I''m trying to find the intersection of a vector and a plane, given three points that comprise the plane. I''ll check out your links, but if this is a different kind of problem any advice is appreciated.Thanks.darrennix@msn.com 0 Share this post Link to post Share on other sites

Guest Anonymous Poster Report post Posted July 22, 2000 And if it helps any, here is the code to test whether a point is in a triangle..It''s in 2D because I wrote a simple app to test the theory. Basically, the point is in the triangle if the point''s angle from each triangle edge is less than the angle of that triangle edge.call: ptinangle for A,B,C; B,C,A; and C,A,Bbool ptinangle(POINT v, POINT v0, POINT v1, POINT v2){ double fTheta = acos(((v.x-v0.x)*(v2.x-v0.x)+(v.y-v0.y)*(v2.y-v0.y))/(mag(v-v0)*mag(v2-v0))), fAngle = acos(((v1.x-v0.x)*(v2.x-v0.x)+(v1.y-v0.y)*(v2.y-v0.y))/(mag(v1-v0)*mag(v2-v0))); if(fTheta < fAngle) return true; return false;}Hope this helps 0 Share this post Link to post Share on other sites

e 122 Report post Posted July 23, 2000 Hey, thanks all for responding.Rowbot: Yeah, I am using that algo. right now, but I was wondering if there was another one (possibly faster).Nate: Thanks for the link. I''ll check it out.Anonymous: Your problem can be solved the same way. Just calculate the plane using the three points you have and then find the intersection of the ray and the plane with this code.Eqtn 1:o = origin of rayd = unit vector (normalized) direction of rayt = -(A * o.x + B * o.y + C * o.z + D) \(A * d.x + B * d.y + C * d.z)If t is negative, the ray and plane never intersect. If the denomiator of the equation is zero, the ray and plane are parallel.Then, to find the intersection point:i = intersection pointi.x = o.x + d.x * ti.y = o.y + d.y * ti.z = o.z + d.z * tHope this helps.-e 0 Share this post Link to post Share on other sites