Search code examples
c#.netdatasetcollision-detectionpolygon

Huge dataset point in polygon in .net (collision detection)


I have a pretty big mesh with polygons, usually triangles but sometimes rectangles. Each point in my mesh has a value (value has nothing to do with coordinates).

Now I am creating a second mesh in the same coordinate-space as the old mesh. I now want to interpolate out values for all points (vertices) in the new mesh using the values from the old mesh.

Now I could loop each polygon in the new mesh and detect which old vertices are in each polygon by making 2d collision detection (altho even this I don't get to function properly so if anyone has simple and fast code for 2d collision detection (triangle is enough) I would gladly see it).

However to my main point again. looping each old vertice for each new polygon seems less than efficient. is there a better way?


Solution

  • What I would suggest as a probable solution without further knowledge about the heuristics of your problem is the following: I would determine the rectangular bounds of the whole scenery, then split this area into equal rectangular partitions, e.g. 100x100. For each partition, you could keep a list of old polygons with vertices in this partition (kind of "hashing" the old polygons). Then you iterate each new polygon, determine which partitions it might touch (you will be fine just using the vertices of the polygon's bounding rectangle and all partitions in between) and lookup your pre-built lists to find the corresponding old vertices which are candidates for exact collision detection.

    This will reduce the number of time consuming exact collision detection calculations but it will certainly increase memory consumption. So depending on your exact problem this could be a good solution or it could be just impractical.