MGH_POLYCLIP
Name
MGH_POLYCLIP
Purpose
Clip an arbitrary polygon on the X-Y plane to a line parallel
to the X or Y axis using the Sutherland-Hodgman algorithm.
Category
Graphics, Region of Interest, Geometry
Calling Sequence
result = MGH_POLYCLIP(poly, clip, dir, neg, COUNT=count)
Return Value
The function returns the clipped polygon as a [2,n] array. The
second dimension will equal the value of the COUNT argument, except
where COUNT is 0 in which case the return value is -1.
POSITIONAL ARGUMENTS
poly (input, floating array)
A [2,m] vector defining the polygon to be clipped.
cval (input, numeric sclar)
The value of X or Y at which clipping is to occur
dir (input, integer scalar)
Specifies whether clipping value is an X (dir = 0) or Y (dir =
1) value.
neg (input, integer scalar)
Set this argument to 1 to clip to the negtive side, 0 to clip to
the positive side.
Keyword Parameters
COUNT (output, integer)
The number of vertices in the clipped polygon.
Procedure
The polygon is clipped using the Sutherland-Hodgman algorithm.
This function is based on JD Smith's implementation of the
Sutherland-Hodgman algorithm in his POLYCLIP function. He can
take all of the credit and none of the blame.
###########################################################################
Copyright (c) 2001-2013 NIWA:
http://www.niwa.co.nz/
Licensed under the MIT open source license:
http://www.opensource.org/licenses/mit-license.php
###########################################################################
Modification History
Mark Hadfield, 2001-10:
Written, based on JD Smith's POLYClIP.
Mark Hadfield, 2013-06:
- The result array is now allocated before looping through the input
vertices, wherease before it was progressively built up by concatenation.
This change results in an enormous speed-up for large (> 10,000) polygons.
- Order of positional arguments changed (poly is now first) to match
MGH_POLYCLIP2.