public class Polygon extends java.lang.Object implements SpatialComparable
Modifier and Type | Field and Description |
---|---|
private double[] |
max
Maximum values
|
private double[] |
min
Minimum values
|
private java.util.List<double[]> |
points
The actual points
|
Constructor and Description |
---|
Polygon(java.util.List<double[]> points)
Constructor.
|
Polygon(java.util.List<double[]> points,
double minx,
double maxx,
double miny,
double maxy)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
java.lang.StringBuilder |
appendToBuffer(java.lang.StringBuilder buf)
Append the polygon to the buffer.
|
double |
areaShoelace()
Compute the polygon area (geometric, not geographic) using the Shoelace
formula.
|
boolean |
containsPoint2D(double[] v)
Point in polygon test, based on
http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
by W.
|
double[] |
get(int idx)
Get a double[] by index.
|
int |
getDimensionality()
Returns the dimensionality of the object.
|
double |
getMax(int dimension)
Returns the maximum coordinate at the specified dimension.
|
double |
getMin(int dimension)
Returns the minimum coordinate at the specified dimension.
|
boolean |
intersects2DIncomplete(Polygon other)
Simple polygon intersection test.
|
ArrayListIter<double[]> |
iter()
Get an iterator to the double[] contents.
|
int |
size()
Get the polygon length.
|
int |
testClockwise()
Test polygon orientation.
|
java.lang.String |
toString() |
private java.util.List<double[]> points
private double[] min
private double[] max
public Polygon(java.util.List<double[]> points)
points
- Polygon pointspublic Polygon(java.util.List<double[]> points, double minx, double maxx, double miny, double maxy)
points
- Polygon pointsminx
- Minimum x valuemaxx
- Maximum x valueminy
- Minimum y valuemaxy
- Maximum y valuepublic ArrayListIter<double[]> iter()
public java.lang.StringBuilder appendToBuffer(java.lang.StringBuilder buf)
buf
- Buffer to append topublic java.lang.String toString()
toString
in class java.lang.Object
public int size()
public double[] get(int idx)
idx
- Index to getpublic int getDimensionality()
SpatialComparable
getDimensionality
in interface SpatialComparable
public double getMin(int dimension)
SpatialComparable
getMin
in interface SpatialComparable
dimension
- the dimension for which the coordinate should be returned,
where 0 ≤ dimension < getDimensionality()
public double getMax(int dimension)
SpatialComparable
getMax
in interface SpatialComparable
dimension
- the dimension for which the coordinate should be returned,
where 0 ≤ dimension < getDimensionality()
public int testClockwise()
public boolean intersects2DIncomplete(Polygon other)
FIXME: while this is found on some web pages as "solution" and satisfies or needs, it clearly is not correct; not even for convex polygons: Consider a cross where the two bars are made out of four vertices each. No vertex is inside the other polygon, yet they intersect.
I knew this before writing this code, but this O(n) code was the simplest thing to come up with, and it would work for our current data sets. A way to fix this is to augment it with the obvious O(n*n) segment intersection test. (Note that you will still need to test for point containment, since the whole polygon could be contained in the other!)
other
- Other polygonpublic boolean containsPoint2D(double[] v)
v
- Point to testpublic double areaShoelace()
Copyright © 2019 ELKI Development Team. License information.