Skip to content

PRITS_TOOLS::VECTOR2POLYGON

Martin Wiesmann edited this page Feb 13, 2024 · 3 revisions

Source code: prits_tools__vector2polygon.pro

Class: PRITS_TOOLS

Description

This function computes the convex hull, a polygon, that encloses all input points. The QHULL procedure is used for this purpose (https://www.nv5geospatialsoftware.com/docs/qhull.html).

Syntax

polygon = PRITS_TOOLS.VECTOR2POLYGON( x [, y] [, xpolygon=xpolygon] [, ypolygon=ypoligon] )

Return value

A 2-dimensional vector of size (2 x nvertices), containing all the coordinates of the vertices of the polygon. The vertices are ordered so that consecutive vertices are connected. The last vertex is connected to the first one.

Arguments

x

Either a 1-dimensional vector giving the x-coordinates of all points that should be in the polygon. Or a 2-dimensional vector of size (2 x npoints) giving the coordinates of all points.

y

A 1-dimensional vector giving the y-coordinates of all points that should be in the polygon. Will be ignored, if x is 2-dimensional

Optional Output

xpolygon

A 1-dimensional vector with the x-components of the vertices of the polygon.

ypolygon

A 1-dimensional vector with the y-components of the vertices of the polygon.

Example usage

points = fix(99*randomu(seed, 2, 33))
vector = prits_tools.vector2polygon(points, xpolygon=xpolygon, ypolygon=ypolygon)

; Plot method A, plotting each line
window, 0
plot, points[0,*], points[1,*], psym=7, color=230, xstyle=2, ystyle=2
for i=0,(size(vector))[2]-1 do begin
  if i eq (size(vector))[2]-1 then ind=0 $
  else ind=i+1
  xvert = [vector[0,i], vector[0,ind]]
  yvert = [vector[1,i], vector[1,ind]]
  oplot, xvert, yvert, color=180
endfor

; Plot method B, computing a mask
window, 1
obj = obj_new('IDLanROI', vector)
mask = obj->ComputeMask(dimensions=[100,100])
pih, mask
print, obj->ContainsPoints([[points], [102,103]])

; Plot method C, filling the polygon
window, 2
polyfill, vector, color=100
oplot, points[0,*], points[1,*], psym=7, color=230
Clone this wiki locally