math & physics
Does anybody know how to find
- the point at where the vector crosses the triangle.
- Vector does not touch the triangle/intersect the triangle.
I have found an explanation on this website
but it does not explain how to find Point P.
Can anybody help me on this.
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.
// 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 )
denum=dot( N,D );
if ( denum==0.0f )
t=dot( N,P0-A );
return A + t*D;
Thanks for your code. I need to clarify some parameters
- I Assume &A, &B are the start point and end point of the line.
- &N is the normal of the plane.
- 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 ?
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
I'm a bit confuse here. In the reply above
"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.
"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.
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.
Thank You very much for your help. I will implement and try it out