Search code examples
c#.net-3.5collision-detectiongdi+graphicspath

Alternative solution to my collision detection with complex shapes?


Situation: I'm currently working on a project that requires collision detection with complex shapes:

example image.

Now the shape as a whole (The black outline) is displayed to the user as a regular image (Using Graphics.DrawImage). The image is broken down into distinct disjoint parts saved and drawn using GraphicsPath. The user clicks on the section, and if the area is clicked then the path is filled in.

Problem: My problem is that on average there is 338 sections for the image.

Example saved data for GraphicsPath for one section:

1:41,1:42,1:43,1:44,1:45,1:46,2:46,3:47,4:47,5:48,6:48,7:48,8:48,9:48,10:48,11:49,12:48,13:48,14:48,15:48,16:48,17:48,18:48,19:48,20:47,21:47,22:47,23:47,24:46,25:46,26:45,27:45,28:44,29:44,30:43,31:43,32:43,33:43,34:43,35:42,36:42,37:43,38:43,39:43,40:43,41:44,42:44,43:44,44:45,45:46,46:46,47:47,48:48,49:48,50:48,51:48,52:48,53:48,53:47,54:47,54:46,54:45,54:44,54:43,54:42,54:41,53:40,53:39,52:38,52:37,52:36,51:35,51:34,50:33,50:32,50:31,50:30,50:29,50:28,50:27,50:26,50:25,50:24,50:23,50:22,51:21,51:20,51:19,51:18,51:17,51:16,50:15,50:14,50:13,50:12,50:11,50:10,50:9,50:8,49:7,49:6,49:5,49:4,48:3,48:2,48:1,47:1,46:1,45:1,44:1,43:1,42:1,41:1,40:1,39:1,38:1,37:1,36:1,35:1,34:1,33:1,32:1,31:1,30:1,29:1,28:2,27:2,26:2,25:2,24:2,23:3,22:3,21:3,20:4,19:4,18:5,17:5,16:6,15:6,15:7,14:7,13:8,12:9,11:10,10:11,10:12,9:13,8:14,8:15,7:16,7:17,7:18,6:19,6:20,6:21,5:22,5:23,5:24,4:25,4:26,4:27,4:28,4:29,3:30,3:31,3:32,3:33,3:34,2:35,2:36,2:37,2:38,2:39,

which is a whole lot of data to save and load into GraphicsPath and then eventually drawn.

Format x:y,...

My question:

Now here is the question, which is really open and I do apologize for. But is there a more elegant solution to this problem? A more simplified version? My supervisor is not thrilled with the solution I've come up with and has instructed me to search for a better one. We're open to using new technology that is compatible with dot net 3.5

Thank-you everyone.


Solution

  • I ended up going with a manual solution. My solution requires the user to define the points. More points = smooth. Less points = more polygon like.