Skip to the navigation links
Last modified: December 2009

URL: http://cxc-newtest.cfa.harvard.edu/ciao4.2/reginsideregion.html
AHELP for CIAO 4.2

regInsideRegion

Context: region

Synopsis

Is a point (or set of points) inside a region?

Syntax

Short_Type regInsideRegion( Region_Type Region, Double_Type X,
Double_Type Y )
Array_Type regInsideRegion( Region_Type Region, Array_Type Xarr,
Array_Type Yarr )

Description

The regInsideRegion routine queries a region to find out if a point (or an array of points) is inside the region or not. 1 is returned for yes, and 0 if no. The input values are a CIAO region variable (as returned from regParse), and the positions to query which can be either a single X, Y position or two arrays of positions, Xarray and Yarray.

The region module is not available by default; to use it in a S-Lang program, it must be loaded using the S-Lang require() function:

  require("region");

Example 1

slsh> require("region");
slsh> reg = regParse("circle(10,10,4)");
slsh> flag = regInsideRegion( reg, 12, 11 );
slsh> print(flag);
1

Here we use the regInsideRegion() routine to find out whether the point at (12,11) is inside the circle centered at (10,10) with a radius of 4 pixels. The answer is 1, since it is.

Example 2

slsh> xc = [ 10, 16, 12 ];
slsh> yc = [ 11, -4, 8 ];
slsh> flag = regInsideRegion( reg, xc, yc );
slsh> print(xc);
10
16
12
slsh> print(yc);
11
-4
8
slsh> print(flag);
1
0
1
slsh> i = where( flag );
slsh> xx = xc[i];
slsh> yy = yc[i];
slsh> print(xx);
10
12
slsh> print(yy);
11
8

Here we have found that the points (10,11) and (12,8) are inside the region, but that (16,-4) is not. The where() routine is then used to show how you can extract from the arrays only those points that lie inside the region. If the where() function had been written

where( flag == 0 )

then it would have selected those points that lie outside the region.

Bugs

See the bugs page for the region library on the CIAO website for an up-to-date listing of known bugs.

See Also

modules
region
region
regarea, regextent, reginsideregion, regparse, regprintregion, regregionstring

Last modified: December 2009