On Mon, Jul 4, 2011 at 2:00 PM, Curtis Jensen <[email protected]>wrote:
> I'm using the RegonFactory.intersection method to get the intersection of
> polygons. However, I'm getting points that are outside of one of the
> original polygons. See example below. Am I misinterpreting what the
> intersection method does, miss-using it, or is this a bug?
>
>
> Vector2D[][] vertices1 = new Vector2D[][] {
> new Vector2D[] {
> new Vector2D(-25.8907, 53.6079),
> new Vector2D(-25.3586, 53.5214),
> new Vector2D(-25.6256, 53.1507),
> new Vector2D(-26.0395, 53.2562)
> }
> };
> PolygonsSet set1 = buildSet(vertices1);
> Vector2D[][] vertices2 = new Vector2D[][] {
> new Vector2D[] {
> new Vector2D(-25.7455, 53.3656),
> new Vector2D(-25.3007, 53.2765),
> new Vector2D(-25.4181, 52.9993),
> new Vector2D(-25.9476, 53.0366)
> }
> };
> PolygonsSet set2 = buildSet(vertices2);
> PolygonsSet intersectionSet = (PolygonsSet) new
> RegionFactory<Euclidean2D>().intersection(set1.copySelf(), set2.copySelf());
>
> Vector2D[][] intersectionVerts = intersectionSet.getVertices();
> for (Vector2D[] set : intersectionVerts) {
> for (Vector2D vertex : set) {
> System.out.println(vertex);
> }
> }
>
>
> OUTPUT:
> {-26.04; 53.26}
> {-25.89; 53.61}
> {-25.36; 53.52}
> {-25.51; 53.32}
> {-25.3; 53.28}
> {-25.42; 53} <- OUTSIDE polygon A
> {-25.72; 53.02} <- OUTSIDE polygon A
> {-25.95; 53.04} <- OUTSIDE polygon A
> {-25.84; 53.21}
>
I should add that the buildSet function is the same as that in the test suit
of commons math:
private PolygonsSet buildSet(Vector2D[][] vertices) {
ArrayList<SubHyperplane<Euclidean2D>> edges = new
ArrayList<SubHyperplane<Euclidean2D>>();
for (int i = 0; i < vertices.length; ++i) {
int l = vertices[i].length;
for (int j = 0; j < l; ++j) {
edges.add(buildSegment(vertices[i][j], vertices[i][(j + 1) %
l]));
}
}
return new PolygonsSet(edges);
}