I have been struggling a bit to get this maths right. I have this image to demonstrate
The whole rectangle is a tile, and I have the position of the mouse inside of this tile. But I want to know when the mouse goes over the red, yellow, green or blue areas.
I know if I do if mouse_x < tile_width/2 and mouse_y < tile_height/2
I can get the coordinates of inside of the pink lines, but I want to know only if the mouse is in the red area.
Let h
and w
be the height and width of the pink rectangle respectively.
The red area is defined by the inequation:
mouse_y < (h / w) * (w - mouse_x)
The blue area is defined by:
mouse_y > (h / w) * mouse_x + h
The yellow area:
mouse_y < (h / w) * mouse_x - h
Can you figure out the green one?