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 coordinates of points Y coordinates of polygon X coordinates of polygon 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.

Procedures: `DPOLYGON`, `PTSINPOLYGON`.

Commands for: Graphics, Spatial statistics.

### Example

```CAPTION   'INSIDE example'; STYLE=meta
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 :