-
How to detect the point of intersection of a Line and a Triangle? (3D)
There is some information but I couldn't figure it out: http://softsurfer.com/Archive/algori...gment-Triangle
How can I detect if a line intersects with a triangle ? And how can I detect the point of intersection in AS3 ?
Last edited by mastermax; 11-28-2010 at 11:19 AM.
-
do your smiles love u?
a triangle forms a plane, like so:
Code:
void SPEMakePlane(SPEVector3 P1, SPEVector3 P2, SPEVector3 P3, SPEVector4 Out){
SPEVector3 a,b;
for(int i=0;i<3;i++){
a[i] = P2[i]-P1[i];
b[i] = P3[i]-P1[i];
}
SPEV3CrossProduct(a, b, Out);
Out[3] = -Out[0]*P1[0]-Out[1]*P1[1]-Out[2]*P1[2];
return;
}
above is c++ code from my engine for deriving the ax+by+cz+d parts of the plane, all stored in an Out vector(anyone see any inefficiency's, or improvements, in the above code please point it out), converting to flash should be fairly easy, after you have the plane do line->plane collision(see solution 2 below):
http://local.wasp.uwa.edu.au/~pbourk...try/planeline/
after which, you then test if that point lies on the triangle:
http://www.blackpawn.com/texts/pointinpoly/default.html
it's pretty straightforward
Last edited by slicer4ever; 11-29-2010 at 03:27 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|