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.

Newcomers DBPro Corner / Finding if a point is in a triangle - Solution

Author
Message
Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 21st Jan 2008 18:20
Hello everyone.

We were learning at school about transformations on an axis, and I got this idea to combine it with finding whether a point is in a triangle or not.

The function:


I know this is bound to die. But I'm posting this for anyone trying to search the forum.
I also did some speed tests, and this method is surprisingly one of the fastest methods.

Attached is a dll with one poor function, namely the one I just gave in DBP code. Include it in Compiler>plugins-user to make it work.
The syntax of the command is:
GetInTriangle(float x1, float y1, float x2, float y2, float x3, float y3, float x, float y)
returns: 1 if (x, y) is in triangle, 0 if not.
The DLL is overall much faster (1000000 times in 303 ms according to my tests on this computer).

And finally an example:


It's the programmer's life:
Have a problem, solve the problem, and have a new problem to solve.

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-11-25 07:24:17
Your offset time is: 2024-11-25 07:24:17