Are there any simple solutions to determine which shapes are touching where the user clicks? I already have a solution to determin the area Id, so I know which shape is touched.
I have thought about trying to walk the line of the shape and adding a couple of X/Y coordinates and creating a hashmap of areas that I find. This seems fairly easy for rectangles, but harder for more complex triangles or circles. Is there a solution that I’m missing?
I’m not aware of any “correct” solution to this problem. But one approach (which I have used successfully) would be to create a bitmap with various shapes drawn in different colours. Then add a click handler for your ImageView, get the x and y coordinates, and find the colour of the pixel at the equivalent spot on the bitmap. This will tell you which shape has been clicked.
I did see the defining colours as a solution to the image map problem. However, I couldn’t see that it helped determine which shapes are bordering the one that has been touched - how do you know that a red shape is touching a green one and a blue one?
The solution with defining the areas as coordinate does work to define areas so that if a user touches an point on the screen, I know that corseponds to area 1. I also need to know whether area 1 borders area 2 and area 3 etc. I could eyeball the image and define these in xml, so I know that area 1 borders area 2 and 3 ie:
Ah yes, sorry I misinterpreted your original post.
The only thing I can think of is, surely there are some existing intersect-detection algorithms on the web. Maybe you could have the shapes overlap each other by 1 pixel, and then simply look up which shapes overlap the clicked area.