math problem related to 3dline and 3dtriangle inte

Community Forums/General Help/math problem related to 3dline and 3dtriangle inte

RemiD(Posted 2016) [#1]
(it would be good to be able to add more chars in the title !)

Hello, :)

I have a problem related to 3dline and 3dtriangle intersection.
Maybe some of you who are math gurus can help me with this ? (please =) )

I already have a way to calculate if a 3dedge (3dline) intersects with a 3dtriangle (thanks EliasT !)
I already understand how to use this to determine if a 3dtriangle intersects with another 3dtriangle.
The good thing is that the formula also returns the intersection point between the 3dline and the 3dtriangle.

I am looking for a way to calculate the 3dline which represents where the 2 3dtriangles intersect

To dermine if a 3dtriangle intersect with another 3dtriangle :

situation1 : if 1 edge of 3dtriangle1 intersects with 3dtriangle2

situation2 : if 2 edges of 3dtriangle1 intersect with 3dtriangle2

situation3 : if 1 edge of 3dtriangle2 intersects with 3dtriangle1

situation4 : if 2 edges of 3dtriangle2 intersect with 3dtriangle1


For situation2 and situation4, i already have the 2 3dpoints of intersection (illustrated in yellow, in cyan) to be able to calculate the 3dline of intersection.

But for situation1 and situation3, i need a formula to find the 3dpoint (illustrated in magenta) to be able to calculate the 3dline of intersection.

Any idea on how to do that ?

(i have access to the 3dposition of each vertex and to the 3dnormal of each 3dtriangle and to the 3dposition of 3dpointofintersection1 (when it exists) and of 3dpointofintersection2 (when it exists))

Thanks,


Floyd(Posted 2016) [#2]
But for situation1 and situation3, i need a formula to find the 3dpoint (illustrated in magenta)

Are you saying that in situation 1 or 3 you can find the yellow point but you need the magenta point?

They look the same to me. Each is the intersection of an edge of one triangle with the interior of the other. The roles of the two triangles are interchanged for magenta point versus yellow point.


RemiD(Posted 2016) [#3]
situation1 and situation3 are the same except the tests are inverted (test if edges of triangle1 intersect with triangle2 or if edges of triangle2 intersect with triangle1 using the ray intersects triangle by EliasT)

situation2 and situation4 are the same except the tests are inverted (test if edges of triangle1 intersect with triangle2 or if edges of triangle2 intersect with triangle1 using the ray intersects triangle by EliasT)

in situation1 and situation3, i have only found one 3dpointofintersection (which could be colored in yellow or cyan depending on the edge concerned) but i don't know how to calculate the 3dpoint in magenta which represents a 3dpoint on the edge of the triangle on which the test is done (using the ray intersects triangle by EliasT)

Knowing the coordinates of this 3dpoint would allow me to calculate the 3dline which represents the area where the 2 3dtriangles intersect.


RemiD(Posted 2016) [#4]
wooops ! i think that i just found the solution by relooking at the illustrations... :P

I just have to calculate if all edges of triangle1 (one at a time) intersect with triangle2 and then calculate if all edges of triangle2 (one at a time) intersect with triangle1, and if no there is no intersection, and if yes there should be 2 intersection 3dpoints and this will allow me to calculate the intersection 3dline... Good ! Thanks me :D


Blitzplotter(Posted 2016) [#5]
This is a great illustration of detecting shapes intersecting with each other, almost a succinct mini tutorial - thanks RemiD for sharing.


Kryzon(Posted 2016) [#6]
Hello. RemiD mentioned some code by Elias_T, which I think is this Code Archive entry:
http://www.blitzbasic.com/codearcs/codearcs.php?code=942

I was curious about the technique involved. It seems to be the Moller-Trumbore method for finding ray-triangle intersections, explained below:
http://www.scratchapixel.com/lessons/3d-basic-rendering/ray-tracing-rendering-a-triangle/moller-trumbore-ray-triangle-intersection

There are also these other resources on point-within-a-triangle tests in 3D:
- http://www.blackpawn.com/texts/pointinpoly/
- http://www.sunshine2k.de/coding/java/PointInTriangle/PointInTriangle.html


RemiD(Posted 2016) [#7]
@Kryzon>>If you are interested about this : the purpose to have the 2 intersection 3dpoints and then to have the intersection 3dline, is to then be able to calculate what i would consider the collision 3dpoint (in the middle of the 3dline).
It can be useful for a 3dshape (made of 3dtriangles) -> 3dshape (made of 3dtriangles) collisions detection system...


Kryzon(Posted 2016) [#8]
Yeah, and using some more algebra you can determine the penetration length, so you can apply it in the opposite way to correct the collision (like making a slide-response).

EDIT: But just to know how to use the math, of course, and how it can be applied to other things in games (like visibility tests etc.).
If I had to do collision detection, I'd use an engine like Bullet which is made by people far smarter than me.