#### Archived

This topic is now archived and is closed to further replies.

# Ray Intersection Problem

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

## Recommended Posts

I have my Ray / Tri intersection test working but I now have a new problem as i bi-product. If my ray strikes a triangle in a model there is also a good chance that the ray will be long enough to strike a second triangle that is directly behind and parellel to the first polgon the ray hit. I need a way of determining which tri is closest to the rays origin. Measuring the distance to each tri''s plane intersection point won''t work i think (prove me wrong please) so i have come up with this : fTriDist = LineSegLength(RayEndPoint, Tri[0]) + LineSegLength(RayEndPoint, Tri[1]) + LineSegLength(RayEndPoint, Tri[2]) / 3; This will work for some polgons but not all. What if you have a large tri which is closest to the ray but has one vertex far away from the ray. This will screw up the scoring system above. How can i best tell the closest triangle to any given point?

##### Share on other sites
If your ray is R(t)=O+D*t then just compare the t values of all the intersections to find the smallest non-negative value, that is your closest intersection.

##### Share on other sites
Ah very good, thx man but what about finding an actual distance value?

[edited by - jonbell on May 26, 2003 8:09:57 AM]

##### Share on other sites
how about learning the basics of vector maths?

there are tons of articles about simple things like that

##### Share on other sites
Well the distance from a point to a triangle is not a trivial calculation to do in real time. Where do you measure it to? Calculating the centre of a triangle and then measuring the vector from the point to the centre is not something you can do thousands of time every second.

"how about learning the basics of vector maths?"

How about learning some manners you fucking arsehole.

##### Share on other sites
Ok,

Search for ray-triangle intersection on the net and you''ll find everything you need.

Basically you first intersect your ray with the plane of the triangle, then you check if the intersection is inside the triangle. This intersection will give you a distance t from your ray origin. Compare t for all triangles you intersect and select the triangle with the minimum positive t.

This is quite basic, optimizations are usally done to minimize the number of intersection tests you need to do. So if this is what you are looking for look for raytracing optimization techniques.

A few good books on ray-tracing are:
"An Introduction To Ray Tracing", Glassner,
"Realistic Ray Tracing", Shirley,
"Object-Oriented Ray Tracing C++", Wilt

/Cheers

##### Share on other sites
well, if you got your ray intersection a triangle working, you''re pretty much there.

you need the triangle plane equation.

Say triangle is (V0, V1, V2)

Normal of triangle is N = ((V1 - V0) x (V2 - V1)) (you should have it already)

your ray equation is P = O + S . t

and P is also on the plane if P * N = (N * V0)

so you have two equations, and you need t.

replace P in the second equation by (O + S . t), and you''ll get

t = ((V0 - O) . N) / (S . N)

I just don;t understand how you managed to get a ray/triangle intersection test working without doing the above calculation, let alone without knowing how to find the intersection of a ray and a plane

1. 1
2. 2
Rutin
24
3. 3
4. 4
JoeJ
18
5. 5

• 14
• 22
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631766
• Total Posts
3002218
×