fabien van mook

all packages "fvm-*"

package "fvm-geometry"

function file "polygonclearance.m"

function Pc = polygonclearance(P,c)
         [Pc,s] = polygonclearance(P,c)

returns a new polygon Pc in which the laterals have a
clearance (or offset) compared with the original polygon
P.

Input matrix P has two or three columns and each row
lists the x and y (and z) coordinates of a vertex by which
the polygon is defined. The vertices are listed in
counter-clockwise ordre, as seen from above the front side
of the polygon surface. Note that the first and last
vertices must not be identical; so, the closure of the
polygon is assumed.

Input scalar c is the clearance distance. The new polygon
Pc has laterals which are at a distance of abs(c) at the
inside of the original polygon P for c > 0, or at the
outside for c < 0.

Alternatively, the input argument c may also be a column
vector of the same number of rows as P. In this case, each
value c(k) defines the clearance distance from its
respective lateral defined by P(k) and P(k+1).

Output scalar s returns the status of the outcome Pc:
  s == 0: the clearance has been succesfully applied.
  s == 1: while matrix P is not empty, it contains less
          than 3 rows and/or does not contain 2 or 3
          columns.
  s == 2: the length of one or more laterals is zero.
  s == 3: the number of elements in c does not match the
          number of laterals in P.
  s == 4: no clearance applied because c contains (all)
          zeros.
  s == 5: due to the clearance applied, vertices have
          been removed.
  s == 6: due to the clearance applied, less than 3
          vertices remained; the new polygon is thus not
          sensible.
  s == 7: due to the clearance applied, the new polygon
          intersects with itself; the new polygon is thus
          not sensible.

If the status is 0 or 5, the clearance has been applied,
and the new polygon Pc is sensible. 

If the status is 4, the new polygon Pc is the same as the
original polygon P.

If the status is 1, 2 or 3, and the output argument s is
not requested, an error message is issued and thus the
program flow is interrupted.

If the output argument s is requested, no error and
warning messages are issued.


(c) 2026 fabien van mook

2026.08.20 release of this file within package "fvm-geometry" under GNU GPLv3+