Vector intersecting triangle

8 replies to this topic

#1elijah

New Member

• Members
• 21 posts

Posted 07 October 2009 - 05:45 AM

Does anybody know how to find
1. the point at where the vector crosses the triangle.
2. Vector does not touch the triangle/intersect the triangle.

I have found an explanation on this website
http://www.cs.prince...cast/sld018.htm

but it does not explain how to find Point P.

Can anybody help me on this.

#2Reedbeta

DevMaster Staff

• 5308 posts
• LocationSanta Clara, CA

Posted 07 October 2009 - 05:55 AM

In the article you linked to, point P is obtained by first intersecting the ray with the plane containing the triangle. If you step back two slides you can see how it goes together.

Anyway, intersecting a vector (really, a line segment) with a triangle should be just a matter of doing a ray-triangle intersection and then checking if the returned 't' value is in the [0, 1] interval, i.e. between the endpoints of the vector.
reedbeta.com - developer blog, OpenGL demos, and other projects

#3rouncer

Senior Member

• Members
• 2722 posts

Posted 07 October 2009 - 10:36 AM

Just use T.
you used to be able to fit a game on a disk, then you used to be able to fit a game on a cd, then you used to be able to fit a game on a dvd, now you can barely fit one on your harddrive.

#4v71

Valued Member

• Members
• 355 posts

Posted 07 October 2009 - 01:42 PM



/////////////////////////////////////////////////

// intersection beetween plane and line

// returns point of intersection

template < class T >

Vec3<T> RayPlaneIntr( Vec3<T> &A ,Vec3<T> &B,  Vec3<T> &P0,Vec3<T> &N )

{

Vec3<T>	D;

T t,denum;

D=B-A;

denum=dot( N,D );

if ( denum==0.0f )

denum=__EPSILON;

t=dot( N,P0-A );

t/=denum;

return A + t*D;

}



#5elijah

New Member

• Members
• 21 posts

Posted 09 October 2009 - 08:32 AM

Hi v71,

Thanks for your code. I need to clarify some parameters
1. I Assume &A, &B are the start point and end point of the line.
2. &N is the normal of the plane.
3. Then what is P0 ? Can it also be the origin of the ray ?

If the line does not intersect, then what will be the value return ?

#6v71

Valued Member

• Members
• 355 posts

Posted 09 October 2009 - 10:53 AM

Well i consider the triangle to be an infinite plane if you need to know if a point is contained inside the triangle, jus ask.
If denum is zero ( it woul be more nice to check for an absolute epsilon , but i found that this worked as well )then the triangle normal and the ray are orthogonal and thus they don't intersect, this condition is never met since i put an epsilon rsulting in a very distant intersection point, then another function checks for the point to be contained inside the triangel itslef.
Your assumptions about the vectors are correct expcet for P0 , it is the origin of the plane where the triangle is inscribed, so
A and B start and end point of ray ( note that this is an infinite ray ) , P0
first point of the triangle and N is its normal.
Since i use this function as an ancillary function, you should do like this if you wnat to improve
check if 0 < t < 1 , in this way you know if the point lies on the ray,
if this check is valid, check for the point ot be contained inside the triangle

#7elijah

New Member

• Members
• 21 posts

Posted 09 October 2009 - 01:32 PM

I'm a bit confuse here. In the reply above

1. "P0 it is the origin of the plane where the triangle is inscribed"
Do you mean the center point of the triangle ? Or the center point of the shape. Inscribed means is a point inside the Triangle.

2. "P0 first point of the triangle"
Do you mean is the first Vertex Point out of the three vertex point that forms a triangle.

It would be great if you could post the code for me to learn.

#8v71

Valued Member

• Members
• 355 posts

Posted 09 October 2009 - 01:36 PM

Assume you have a triangle , composed by 3 vertices , P0,P1,P2
the N vector is the cross product of 2 vectors namely U and V
U = P1-P0 and V=P2-P0;
in that function i assume that N is already computed
so , that you have a plane where this triangle lies in , P0 is a point on this plane and N is its normal.

#9elijah

New Member

• Members
• 21 posts

Posted 09 October 2009 - 02:40 PM

Thank You very much for your help. I will implement and try it out

1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users