Skip to content

dist2bdry.m

Basic Information

  SYNTAX:  [distance,nearest_pt] = dist2bdry(bdry,point,closed)

  PURPOSE:  Compute (min) distance from a point to a boundary.  Boundary
    is assumed be defined by the vertices specified in bdry and by linear
    interpolation between these points, in the order specified.

  INPUT:
    bdry = n x 2 array specifying x,y pairs which define boundary
    point = [x,y] data point
    closed = set to 1 if first and last vertex in bdry list should be
            connected to form a closed boundary(optional,default=0)

  OUTPUT:
    distance = minimum distance from point to boundary
    nearest_pt = [x,y] point on boundary nearest to point specified

  RESTRICTIONS:
   (1) Works for "normal" cases where you can locate the closest
   boundary point by first finding the first vertex on boundary.  Won't work
   for "pathological" cases where boundary closest to the point is defined by
   two vertices far away from the point.
   (2) Not well tested yet. (Not at all for closed boundaries.)

Dependencies