Line vs Triangle collision in 3D

Started by
13 comments, last by Eck 9 years, 7 months ago


Right now it is like when you are a fisherman and you meet a starwing painter and he asks you for food and you are like: "Listen here dude, i wont give you any fish but ill teach you how to fish.". In short, im working on something totaly out of my league and i need some quick fix for it, i can't afford to learn to understand how it works.

Except that I offer to feed the fisherman and tell him I'll even give him the fish today AND teach him to fish if he can describe why he's in this position in the first place. But the painter storms off to start pestering other fisherman.


I guess i was hopping to get a done function that i could just copy paste, this may sound kind of selfish but i don't realy have any choice here, got like two days to finish this program, therefor no time to do it right.

I'm genuinely curious why you need this and only have 2 days to do it. It doesn't sound like you're in school, so perhaps it's a take-home interview assignment? If so, then you should really get to the solution on your own with guidance rather than just being handed a solution. If I didn't guess right, then please tell me why.

You do have a choice. Two days is PLENTY of time to teach you how to write this function and understand why it works. If you can take 5 minutes of that deadline and explain more details about your situation, I'll be more than happy to give you the fish and teach you how to fish. (provided I agree with the why)

- Eck

EckTech Games - Games and Unity Assets I'm working on
Still Flying - My GameDev journal
The Shilwulf Dynasty - Campaign notes for my Rogue Trader RPG

Advertisement

I'm just guessing right now, so this might be wrong:

First check if the line ever passes the triangle, if yes, take the point where the line passes the triangle and make three more triangles with each of the points of the original triangle and the point like so:

7zog0Lp.png

If the area of the three triangles is equal to the area of the larger triangle, you have yourself an intersection.

I actually had a quick glimpse at a youtube video talking about this kind of intersection, thought it might be worth sharing my two cents.

Edit: Here's the video:

I'm genuinely curious why you need this and only have 2 days to do it. It doesn't sound like you're in school, so perhaps it's a take-home interview assignment? If so, then you should really get to the solution on your own with guidance rather than just being handed a solution. If I didn't guess right, then please tell me why.

You do have a choice. Two days is PLENTY of time to teach you how to write this function and understand why it works. If you can take 5 minutes of that deadline and explain more details about your situation, I'll be more than happy to give you the fish and teach you how to fish. (provided I agree with the why)

- Eck

It were 5 days for the whole Test, not just for this function and i did set the time limit myself when i started it. Basically i was trying to write a small simulation in unity3d. Funny is that i found out later that unity3d framework already contains this function, not just for Ray's but for Line's as well ^^

I'm just guessing right now, so this might be wrong:

First check if the line ever passes the triangle, if yes, take the point where the line passes the triangle and make three more triangles with each of the points of the original triangle and the point like so ...

If the area of the three triangles is equal to the area of the larger triangle, you have yourself an intersection.

I actually had a quick glimpse at a youtube video talking about this kind of intersection, thought it might be worth sharing my two cents.

Thanks for that, i like when tutorials have some simply graphic's, i think i understand it better now.

Thanks for that, i like when tutorials have some simply graphic's, i think i understand it better now.


You're welcome! The thing is, I've never actually done anything in 3d so this is completely theoretical... would be logical though.

Also I would be interested to know how one would find the position where the line and triangle pass each other, I could probably figure it out for 2d but it seems more complex for 3d.If anyone knows, would be great to note into my reference book.

Careful using this method with computers though since floating point numbers aren't perfect. There's likely to be some rounding error when calculating the sums of the triangles' areas.

Here's an article that explains how another algorithm works.

http://geomalgorithms.com/a06-_intersect-2.html

I'd have shared it earlier, but it has a C++ solution at the end and I wanted to make sure you weren't "cheating". :)

- Eck

EckTech Games - Games and Unity Assets I'm working on
Still Flying - My GameDev journal
The Shilwulf Dynasty - Campaign notes for my Rogue Trader RPG

This topic is closed to new replies.

Advertisement