How to represent a polygon with hole(s)?

前端 未结 6 1887
野趣味
野趣味 2021-01-02 10:17

It\'s usually popular to work with polygons with their vertices sorted CW or CCW in vectors(2*1 or 1*2 matrices). However, how to state polygons with holes in vectors?

6条回答
  •  星月不相逢
    2021-01-02 11:14

    As others have mentioned, a polygon with holes can be represented as an exterior boundary, plus zero or more interior boundaries, all of which are mutually nonoverlapping*. If you use nonzero winding number to determine inside/outside, be sure to specify your interior boundaries in the opposite direction as the exterior boundaries (counterclockwise for exterior and clockwise for interior, or vice-versa) so that the contour integrals are zero inside the holes.

    FYI, tis kind of definition/representation has been formalized in the OpenGIS Simple Features Specification (PDF).

    As far as representation:

    I'd probably have a cell array of K Nx2 matrices, where the first element in the cell array is the exterior boundary, and the remaining elements (if any) in the cell array are the interior boundaries. I would use a cell array because there may not be the same number of points on each boundary.

    *nonoverlapping = except at individual points, e.g. a diamond inside a square:

    alt text alt text

提交回复
热议问题