subtract
Boolean difference of two polyshapes: the first with the second cut out.
Category: Mathematics > Computational Geometry
Syntax
P = subtract(P1, P2)
Returns the part of P1 that is not in P2.
Description
If P2 lies fully inside P1, the result is P1 with a hole. If it cuts across an edge, a notch is removed. If they do not overlap, P1 is returned unchanged. The order of arguments matters: subtract(P1, P2) and subtract(P2, P1) are different shapes.
The companion operations are union, intersect and xor.
Input arguments
P1- The
polyshapeto cut from. P2- The
polyshapeto remove.
Output arguments
P- The difference, as a new
polyshape. It can have holes or several regions.
Example
Punching a hole
P = polyshape([0 4 4 0], [0 0 3 3]);
H = polyshape([1 2 2 1], [1 1 2 2]);
D = subtract(P, H);
D.NumHoles
area(D)
Output
ans = 1
ans = 11