poly_poly_clipΒΆ
poly_poly_clip calculates the intersections between a polygon (open polygon) and a data hull (closed polygon).
-
<rmXY, idx> = poly_poly_clip(nOpt, clip, poly)
Return Value
rmXY, idx: rmXY is a matrix with two columns. The first column contains the x-coordinates and the second column the y-coordinates of the result polygon. idx is an index vector with the end points of the polygons (see example).
Parameters
-
nOpt
nOpt specifies what result should be computed. nOpt can be one of the following values:
Value | Meaning |
---|---|
0 | union (hull containing both polygons). |
1 | difference (part of the subject polygon that is inside the clip hull). |
2 | difference (part of the subject polygon that is inside the clip hull). |
3 | hull without subject polygon. |
-
clip
clip are the x/y-coordinates of the clip polygon. The coordinates must be given as a complex vector (x + 1i*y) (see example).
-
poly
poly are the x/y-coordinates of the subject polygon. The coordinates must be given as a complex vector (x + 1i*y) (see example).
Example
def test(option)
{
xhull = [1, 1, 2, 2, 1];
yhull = [1, 2, 2, 1, 1];
nh = len(xhull)
h = plot(xhull,yhull)
xp = [1.3, 1.3, 1.6, 1.6, 1.3];
yp = [0.3, 2.6, 2.6, 0.3, 0.3];
<xy, idx> = poly_poly_clip(option, xhull[1:nh] + 1i * yhull[1:nh], xp + 1i*yp);
if (len(idx) == 1 && idx[1] == 0) {
return TRUE;
}
nPoly = len(idx);
if (len(xy) > 1) {
idx = [0;idx];
for (i in 2:nPoly+1) {
h = plot(xy[idx[i-1]+1:idx[i]; 1], xy[idx[i-1]+1:idx[i];2], h[2]);
}
}
return xy;
}
See also
id-1848134