Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Point in triangle function?

Author
Message
Aurum Knight
18
Years of Service
User Offline
Joined: 15th Jul 2008
Location: the suburbs of nowhere
Posted: 15th Jan 2011 00:30 Edited at: 15th Jan 2011 00:31
Does anyone know of a simple function that tests whether a point is in or touching a triangle? I've tried some versions from this site that I found, but every one I've tried invariably doesn't work in some way or another. I just spent several hours debugging code only to find that the point-in-triangle function that I was sure worked, didn't.

Here are two that I found (that don't work in some way or another):


I didn't want to post before because it seemed like such a ridiculously easy thing to have to ask for help with, but none of the functions I've tried work. It was hard enough finding these functions as it is.
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 15th Jan 2011 01:27 Edited at: 15th Jan 2011 01:31
Check the bottom of my "Intersections" section for an explanation of the following code:
http://dbcodecorner.com/?page=eq




Hmm, looks like you may have tried this method. But the code I posted does work, I just tested it.

edit:
Hate to break it to ya Aurum Knight, but I've tested the two functions you posted above and both worked just fine for me. Whatever issue you're having in your code it's not with the point in triangle function.

"Only the educated are free" ~Epictetus
"Imagination is more important than knowledge..." ~Einstein
Aurum Knight
18
Years of Service
User Offline
Joined: 15th Jul 2008
Location: the suburbs of nowhere
Posted: 15th Jan 2011 04:29 Edited at: 15th Jan 2011 05:40
Thanks for looking at this Phaelax. I was sure both didn't work, but it turns out the second one, which I wasn't using, worked after all after I retested it. I know I didn't just replace it for no reason... maybe it was a bug somewhere else that messed it up when I tested the second one, or something...

In any case, thanks

The first one on the other hand doesn't. Here's the test I made that tests against the mouse, with yours being function number 3. They appear to work at first until you change the order of the vertexes twice (by hitting space).



EDIT:
It turns out it did have another problem when something was exactly on the corner. I added code to compare the point against the three vertexes though, and now it works fine. Such an annoying function though, heh.

Login to post a reply

Server time is: 2026-07-21 15:13:56
Your offset time is: 2026-07-21 15:13:56