M-File Help: Polygon | View code for Polygon |
Polygon class
A general class for manipulating polygons and vectors of polygons.
plot | Plot polygon |
area | Area of polygon |
moments | Moments of polygon |
centroid | Centroid of polygon |
perimeter | Perimter of polygon |
transform | Transform polygon |
inside | Test if points are inside polygon |
intersection | Intersection of two polygons |
difference | Difference of two polygons |
union | Union of two polygons |
xor | Exclusive or of two polygons |
display | print the polygon in human readable form |
char | convert the polgyon to human readable string |
vertices | List of polygon vertices, one per column |
extent | Bounding box [minx maxx; miny maxy] |
n | Number of vertices |
The methods inside, intersection, difference, union, and xor are based on code written by:
Kirill K. Pankratov, kirill@plume.mit.edu, http://puddle.mit.edu/~glenn/kirill/saga.html
and require a licence. However the author does not respond to email regarding the licence, so use with care, and modify with acknowledgement.
Polygon class constructor
p = Polygon(v) is a polygon with vertices given by v, one column per vertex.
p = Polygon(C, wh) is a rectangle centred at C with dimensions wh=[WIDTH, HEIGHT].
Area of polygon
a = P.area() is the area of the polygon.
Centroid of polygon
x = P.centroid() is the centroid of the polygon.
String representation
s = P.char() is a compact representation of the polgyon in human readable form.
Difference of polygons
d = P.difference(q) is polygon P minus polygon q.
Display polygon
P.display() displays the polygon in a compact human readable form.
Test if points are inside polygon
in = p.inside(p) tests if points given by columns of p are inside the polygon. The corresponding elements of in are either true or false.
Intersection of polygon with list of polygons
i = P.intersect(plist) indicates whether or not the Polygon P intersects with
i(j) = 1 if p intersects polylist(j), else 0.
Intersection of polygon and line segment
i = P.intersect_line(L) is the intersection points of a polygon P with the line segment L=[x1 x2; y1 y2]. i is an Nx2 matrix with one column per intersection, each column is [x y]'.
Intersection of polygons
i = P.intersection(q) is a Polygon representing the intersection of polygons P and q.
Input checking for line segments.
Moments of polygon
a = P.moments(p, q) is the pq'th moment of the polygon.
Perimeter of polygon
L = P.perimeter() is the perimeter of the polygon.
Plot polygon
P.plot() plot the polygon.
P.plot(ls) as above but pass the arguments ls to plot.
Transformation of polygon vertices
p2 = P.transform(T) is a new Polygon object whose vertices have been transfored by the 3x3 homgoeneous transformation T.
Union of polygons
i = P.union(q) is a Polygon representing the union of polygons P and q.
Exclusive or of polygons
i = P.union(q) is a Polygon representing the union of polygons P and q.
© 1990-2012 Peter Corke.