GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • » Octave core
  • » by package
  • » alphabetical

This view

  • Original page
  • New address

GeezerVison is showing octave.sourceforge.io — Function Reference: inpolygon

Octave-Forge - Extra packages for GNU Octave
Home · Packages · Developers · Documentation · FAQ · Bugs · Mailing Lists · Links · Code

Navigation

Operators and Keywords

Function List:

  • » Octave core
  • » by package
  • » alphabetical

C++ API

: in = inpolygon (x, y, xv, yv)
: [in, on] = inpolygon (x, y, xv, yv)

For a polygon defined by vertex points (xv, yv), return true if the points (x, y) are inside (or on the boundary) of the polygon; Otherwise, return false.

The input variables x and y, must have the same dimension.

The optional output on returns true if the points are exactly on the polygon edge, and false otherwise.

See also: delaunay.

Demonstration 1

The following code

 xv = [ 0.05840, 0.48375, 0.69356, 1.47478, 1.32158, ...
        1.94545, 2.16477, 1.87639, 1.18218, 0.27615, ...
        0.05840 ];
 yv = [ 0.60628, 0.04728, 0.50000, 0.50000, 0.02015, ...
        0.18161, 0.78850, 1.13589, 1.33781, 1.04650, ...
        0.60628 ];
 xa = [0:0.1:2.3];
 ya = [0:0.1:1.4];
 [x,y] = meshgrid (xa, ya);
 [in,on] = inpolygon (x, y, xv, yv);
 inside = in & ! on;

 clf;
 plot (xv, yv);
 hold on;
 plot (x(inside), y(inside), "@g");
 plot (x(! in), y(! in), "@m");
 plot (x(on), y(on), "@b");
 hold off;
 disp ("Green points are inside polygon, magenta are outside,");
 disp ("and blue are on boundary.");

Produces the following output

Green points are inside polygon, magenta are outside,
and blue are on boundary.

and the following figure

Figure 1

Demonstration 2

The following code

  xv = [ 0.05840, 0.48375, 0.69356, 1.47478, 1.32158, ...
         1.94545, 2.16477, 1.87639, 1.18218, 0.27615, ...
         0.05840, 0.73295, 1.28913, 1.74221, 1.16023, ...
         0.73295, 0.05840 ];
  yv = [ 0.60628, 0.04728, 0.50000, 0.50000, 0.02015, ...
         0.18161, 0.78850, 1.13589, 1.33781, 1.04650, ...
         0.60628, 0.82096, 0.67155, 0.96114, 1.14833, ...
         0.82096, 0.60628];
 xa = [0:0.1:2.3];
 ya = [0:0.1:1.4];
 [x, y] = meshgrid (xa, ya);
 [in, on] = inpolygon (x, y, xv, yv);
 inside = in & ! on;

 clf;
 plot (xv, yv);
 hold on;
 plot (x(inside), y(inside), "@g");
 plot (x(! in), y(! in), "@m");
 plot (x(on), y(on), "@b");
 hold off;
 disp ("Green points are inside polygon, magenta are outside,");
 disp ("and blue are on boundary.");

Produces the following output

Green points are inside polygon, magenta are outside,
and blue are on boundary.

and the following figure

Figure 1

Package: octave

SourceForge.net Logo
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.