polybuffer

Grows or shrinks a polyshape by a fixed distance.

Category: Mathematics > Computational Geometry

Syntax

pb = polybuffer(pshape, d)

Offsets the boundaries by distance d: outward for positive d, inward for negative.

pb = polybuffer(pshape, d, 'JointType', type)

Chooses how the corners are treated: 'round' (default), 'square' or 'miter'.

Description

The buffer is the set of points within distance d of the shape. For a rectangle of 4 by 3 grown by 1 with round corners, the area is 12 + 14*1 + pi: the original, four strips along the sides, and four quarter discs at the corners. Miter joints keep sharp corners, so the area grows to 30 for the same example.

Holes shrink as the shape grows, and close up when the offset exceeds their size.

Input arguments

pshape
A polyshape object.
d
Offset distance. A negative value shrinks the shape and may make it vanish or split.
'JointType'
Corner style. Round corners are arcs of radius d, miter corners keep the sharp angle, square corners are cut flat.

Output arguments

pb
The offset polyshape.

Example

Round and miter growth

P = polyshape([0 4 4 0], [0 0 3 3]);
rounded = polybuffer(P, 1);
mitered = polybuffer(P, 1, 'JointType', 'miter');
fprintf('%.4f\n', area(rounded), area(mitered))
Output
29.1410
30.0000

See also

polyshape area perimeter rmslivers