1. Home
  2. INSIDE procedure

INSIDE procedure

Determines whether points lie within a specified polygon (S.A. Harding).

Option

TOLERANCE = scalar Value used for testing against zero; default 10-4

Parameters

Y = variates Y coordinates of points
X = variates X coordinates of points
YPOLYGON = variates Y coordinates of polygon
XPOLYGON = variates X coordinates of polygon
INSIDE = variates Indicate whether points are inside (1) the polygon, outside (-1) or on an edge (0)

Description

INSIDE takes a set of points whose x and y coordinates are specified by the X and Y parameters and determines which of these lie inside the polygon whose vertices are specified by the XPOLYGON and YPOLOGON parameters. This procedure is primarily intended for use with high-resolution graphics. It allows subsets of plotted points to be identified according to their spatial relationships so that they can be redrawn or deleted.

The output is in the form of a variate, specified by the INSIDE parameter. This will contain the value 1 for points that are located inside the polygon, 0 for those on an edge, and -1 for those outside the polygon. It can thus be used in RESTRICT, for example, to identify subsets of the values.

Usually the polygon will be defined by several points. Closure is assumed, so the last point need not be the same as the first. The polygon need not be convex. If only two points are given these are interpreted as diagonally opposite corners of a rectangle (thus maintaining compatibility with the “rubber-rectangle” type of input cursor of DREAD).

Option: TOLERANCE.

Parameters: Y, X, YPOLYGON, XPOLYGON, INSIDE.

Method

The method used is essentially that of Shimrat (1962). The algorithm counts the number of edges for which a point lies within the y-range and to the left. If this is an odd number the point must lie within the polygon. A separate check is made for points that lie on the boundary.

Action with RESTRICT

If either Y or X variate is restricted, only the restricted set of points is checked for inclusion in the polygon. Any points omitted by a restriction will be identified as lying outside the polygon. Restrictions are removed from YPOLYGON and XPOLYGON.

Reference

Shimrat, M. (1962). Position of point relative to polygon, CACM Algorithm 112. Communications of the ACM, August 1962.

See also

Procedures: DPOLYGON, PTSINPOLYGON.

Commands for: Graphics, Spatial statistics.

Example

CAPTION   'INSIDE example'; STYLE=meta
READ      SLength,SWidth
1.4 0.2 4.7 1.4 1.4 0.2 4.5 1.5 1.3 0.2 4.9 1.5 1.5 0.2 4.0 1.3
1.4 0.2 4.6 1.5 1.7 0.4 4.5 1.3 1.4 0.3 4.7 1.6 1.5 0.2 3.3 1.0
1.4 0.2 4.6 1.3 1.5 0.1 3.9 1.4 1.5 0.2 3.5 1.0 1.6 0.2 4.2 1.5
1.4 0.1 4.0 1.0 1.1 0.1 4.7 1.4 1.2 0.2 3.6 1.3 1.5 0.4 4.4 1.4
1.3 0.4 4.5 1.5 1.4 0.3 4.1 1.0 1.7 0.3 4.5 1.5 1.5 0.3 3.9 1.1
1.7 0.2 4.8 1.8 1.5 0.4 4.0 1.3 1.0 0.2 4.9 1.5 1.7 0.5 4.7 1.2
1.9 0.2 4.3 1.3 1.6 0.2 4.4 1.4 1.6 0.4 4.8 1.4 1.5 0.2 5.0 1.7
1.4 0.2 4.5 1.5 1.6 0.2 3.5 1.0 1.6 0.2 3.8 1.1 1.5 0.4 3.7 1.0
1.5 0.1 3.9 1.2 1.4 0.2 5.1 1.6 1.5 0.2 4.5 1.5 1.2 0.2 4.5 1.6
1.3 0.2 4.7 1.5 1.4 0.1 4.4 1.3 1.3 0.2 4.1 1.3 1.5 0.2 4.0 1.3
1.3 0.3 4.4 1.2 1.3 0.3 4.6 1.4 1.3 0.2 4.0 1.2 1.6 0.6 3.3 1.0
1.9 0.4 4.2 1.3 1.4 0.3 4.2 1.2 1.6 0.2 4.2 1.3 1.4 0.2 4.3 1.3
1.5 0.2 3.0 1.1 1.4 0.2 4.1 1.3 :
READ      yp1,xp1
2.723 0.998 4.067 0.770 5.299 1.453 5.299 1.869 4.602 1.882 2.723 1.004 :
READ      yp2,xp2
0.90 0.03 2.09 0.03 2.1 0.5 1.52 0.81 0.84 0.21 0.84 0.04 0.89 0.03 :
INSIDE    SLength; SWidth; yp1; xp1; in1
INSIDE    SLength; SWidth; yp2; xp2; in2
CALCULATE pens = (in1.ge.0) + 2*(in2.ge.0)
PEN       3; METHOD=line; JOIN=given; SYMBOL=0
DGRAPH    SLength,yp1,yp2; SWidth,xp1,xp2; PEN=pens,3,3
Updated on March 7, 2019

Was this article helpful?