How to determine which triangle touched the user in this rectangle?

I made an Android custom view that looks like a D-Pad (image below). Given the indirect coordinate (x, y), the width of the rectangle (w) and the height of the rectangle (h), ignoring the white diagonal and rounded corners, can someone help me how to determine which triangle to touch the user?

Additional information: (0,0) - upper left corner

D-Pad Image

+4
source share
1 answer

: w/2 x h/2 y. ( w , h), : x *= h; x /= w; :

x < 0, |y| < |x| = left
x > 0, |y| < |x| = right
y < 0, |x| < |y| = up
y > 0, |x| < |y| = down

( , x = y = 0, | x | = | y |, , ).

+3

Source: https://habr.com/ru/post/1622282/


All Articles