Package adams.data.geometry
Class PolygonUtils
- java.lang.Object
-
- adams.data.geometry.PolygonUtils
-
public class PolygonUtils extends Object
Helper class for polygons.- Author:
- fracpete (fracpete at waikato dot ac dot nz)
-
-
Constructor Summary
Constructors Constructor Description PolygonUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static PolygonaddVertext(Polygon poly, Point vertex)Adds the vertex to the polygon at the appropriate position.static RectangleboundingBox(List<Point> points)Returns the bounding box for the polygon.static Polygoninc(Polygon p, int incX, int incY)Increments/decrements the x/y coordinates of the polygon.static intinside(Polygon outer, Polygon inner)Determines the number of x/y pairs of the inner polygon that fall inside the outer polygon.static doubleminDistance(Point A, Point B, Point E)Returns the minimum distance between a line segment AB and a point E.static booleanoverlap(Polygon p1, Polygon p2, boolean fully)Checks whether the polygons overlap.static List<Point>toPoints(Polygon poly)Turns the polygon into a list of points.static PolygontoPolygon(Rectangle rect)Turns the rectangle into a polygon.static PolygontoPolygon(List<Point> points)Returns the bounding box for the polygon.
-
-
-
Method Detail
-
toPolygon
public static Polygon toPolygon(List<Point> points)
Returns the bounding box for the polygon.- Parameters:
points- the polygon points to calculate the bounding box for- Returns:
- the polygon
-
toPolygon
public static Polygon toPolygon(Rectangle rect)
Turns the rectangle into a polygon.- Parameters:
rect- the polygon to convert- Returns:
- the polygon
-
toPoints
public static List<Point> toPoints(Polygon poly)
Turns the polygon into a list of points.- Parameters:
poly- the polygon- Returns:
- the list of points
-
boundingBox
public static Rectangle boundingBox(List<Point> points)
Returns the bounding box for the polygon.- Parameters:
points- the polygon points to calculate the bounding box for- Returns:
- the bbox
-
minDistance
public static double minDistance(Point A, Point B, Point E)
Returns the minimum distance between a line segment AB and a point E.- Parameters:
A- the start of the line segmentB- the end of the line segmentE- the point to calculate the min distance to- Returns:
- the minimum distance
-
addVertext
public static Polygon addVertext(Polygon poly, Point vertex)
Adds the vertex to the polygon at the appropriate position.- Parameters:
poly- the polygon to add tovertex- the vertex to insert- Returns:
- the new polygon
-
inside
public static int inside(Polygon outer, Polygon inner)
Determines the number of x/y pairs of the inner polygon that fall inside the outer polygon.- Parameters:
outer- the outer polygoninner- the inner polygon- Returns:
- the number of pairs that fall inside
-
overlap
public static boolean overlap(Polygon p1, Polygon p2, boolean fully)
Checks whether the polygons overlap.- Parameters:
p1- the first polygonp2- the second polygonfully- whether one polygon must be fully contained by the other- Returns:
- true if they overlap
-
-