Friday, 15 June 2012

c - Library / Data Structure to store convex polygon with holes -


I want to map a building. This area is a convex polygon in which there are several non-overlapping convex holes. As a simplification, the area can also be expressed as a rectangle. The hole can also be prepared as a rectangle.

I tried to handle it with GOOS, a C ++ library, which comes with low level C API. But it appears GOOS is not capable of handling the amount of requests.

What is the best data structure to handle the map? Maybe a Chaudhary? Is there a ready-to-use library (beyond the academic proof of concept stage)? Library should be C (not C ++)

Store the map as a list of directed line segments (so that we can determine whether We are behind or behind a segment):

  Structure Segment {Pos2 p0; Pos2 p1; Ent Hole Index; // what division this segment divides};  

Then divide the segments into one:

struct BSPNode {Segment split; BSPNode * infront; BSPNode * Back; };

Then you can find the hole with this code:

  int findHole (BSPNode * node, pos2 pos) {if (! Node-> Back ) {// This node is a leaf (if previous (pause2, node-> division)) {return node-> Partition- & gt; Hole index; } And {return -1; // Point is not in a hole}} If (is, (pause2, node-> division is)) {return search (node-> behind, position); } Else {return findHole (node-> infron, pos); }} Int hole = findHole (root, some POS); If it is  is  such a case that each hole has a single rectangle, then you can make a rectangular hole set by bisp by making a rectangle in each division.    struct BSPNode {union} rectangle rectangle; // Lead node guidedline splitter; // branch node}; BSPNode * infront; // If the tap indicates that it is a leaf node BSPNode * behind; }; Int SearchHole (BSPNode * Node, POS 2 Pauses) {if (! Node-> Back) {// This node is a leaf if (Inside (Pause 2, node-> Rectangle)) {return node- & Gt; Rectangle->; HoleIndex; } And {return -1; // Point is not in a hole}} (if (after 2, node-> splitter)) (return search hole (node-> behind, position);} Else {return findHole (node-> infron , Pos);}}  

No comments:

Post a Comment