Presumably, you will need to have a tree structure if you want it to be as general as possible (i.e. polygons with polygonal holes, inside which there are polygons with holes inside ...). Matlab is not very good at representing tree structures efficiently, but here is one idea ...
Have a structural array of polygons.
Each polygon is a structure with two fields, “corners” and “children”.
The "corners" field contains the matrix of coordinates (x, y) of the corners, accessed as "data {polyIdx} .corners (:, cornerIdx)".
The "children" field is a structural array of polygons.
Here is an example of some code to make a triangle with dummy children that are holes (they are really not valid, although they will probably overlap:
polygon = struct; npoints = 3; polygon.corners = rand(2,npoints); polygon.children = struct; nchildren = 5; for c=1:nchildren polygon.children(c).corners = rand(2,npoints); polygon.children(c).children = struct; end
You can continue to recursively identify children that alternate between creating holes and filling them.
Mr Fooz
source share