Page 1 of 1

How to check if touch press is in a triangle [SOLVED]

Posted: Sun Apr 21, 2019 10:20 am
by test
I use love.graphics.polygon to draw triangles. But how can I check if touch press is in a triangle?

Re: How to check if touch press is in a triangle

Posted: Sun Apr 21, 2019 12:42 pm
by zorg
Simple. You need to detect a collision between a triangle shape and a point. Löve doesn't have a built-in function for that. The internet has tons of examples though, just search it and adapt the code to lua.

Re: How to check if touch press is in a triangle

Posted: Mon Apr 22, 2019 6:25 am
by ivan
Point in triangle is a relatively simple check:
https://2dengine.com/?p=intersections#P ... e_triangle
If you want the touch area to be larger (circle) then it's slightly more complicated:
https://2dengine.com/?p=intersections#C ... s_triangle