Detect point in triangle (2D) - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1) +--- Forum: Prolific Programmers (https://qb64phoenix.com/forum/forumdisplay.php?fid=26) +---- Forum: Petr (https://qb64phoenix.com/forum/forumdisplay.php?fid=52) +---- Thread: Detect point in triangle (2D) (/showthread.php?tid=3221) |
Detect point in triangle (2D) - Petr - 11-20-2024 Hi. I needed to write a function for arrows in the game Puzzle and from that came the need to write or get a function for detecting a point in a triangle. I found a beautiful solution in C++. So I am attaching the original source code in C++ but of course also my version in QB64 which is based on it. The source code also includes a link to the original source. I think it might be useful for someone someday (and I also know that I will save it on my computer so that I can find it, so I will never find it again). I tried some combinations of points and it seems to work correctly. If you encounter a problem, write it here. I am not entirely sure of the meaning of the last line in C++: return d == 0 || (d < 0) == (s + t <= 0); and it is possible that I did not understand it correctly. I am not good with C++. Code: (Select All)
RE: Detect point in triangle (2D) - bplus - 11-20-2024 Wow I was just looking at MasterGy's PointInTriangle here: https://qb64phoenix.com/forum/showthread.php?tid=2134 last night. Looks like a common task needed from comments to his and now yours. RE: Detect point in triangle (2D) - Petr - 11-20-2024 Hi BPlus, I didn't know that. I could have saved myself some time Yeah, MasterGy is very good. Thanks for the link. |