commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Curtis Jensen <cur...@the-jensens.org>
Subject [math] Polygon Difference Question
Date Fri, 26 Aug 2011 18:41:08 GMT
Using math 3.0, I have two polygons with many points.  One is
completely contained within the other.  When I do a difference on the
two, I expected to get a polygon with a hole in it.  However, I get 86
polygons, that roughly make up a polygon with a hole in it.  If I
scale the points by a factor of 0.1, I get 7 polygons, and if I scale
it differently in the two directions, I get a different number of
polygons.  Sometimes the resultant polygons don't seem to make a shape
resembling a polygon with a hole in it.

How should I interpret the results of the difference method?  i.e. How
do I process the 86 or 7 or however many polygons so that it resembles
1 polygon with 1 hole in it?

Thanks,
Curtis


Attached are two csv files with the points in CCW order.  Also
attached is a plot of the points in the two files.  Below is code I
added to the org.apache.commons.math.geometry.euclidean.twod.PolygonsSetTest
class to test with (It uses the Apache Common FileUtils too)



   @Test
    public void testDifferenceManyPoints() throws IOException {
    	PolygonsSet set1 = csv2set(new File("src_ccw.csv"));
    	PolygonsSet set2 = csv2set(new File("inner_ccw.csv"));
    	
    	PolygonsSet set  = (PolygonsSet) new
RegionFactory<Euclidean2D>().difference(set1.copySelf(),
set2.copySelf());
    	Vector2D[][] verts = set.getVertices();
    	System.out.println(verts.length);
    }

    private PolygonsSet csv2set(File file) throws IOException {
		List linesObj = FileUtils.readLines(file);
		
		Vector2D[][] verts = new Vector2D[1][linesObj.size()];
		for (int i = 0; i < linesObj.size(); i++) {
			String line = (String)linesObj.get(i);
			String[] tokens = line.split(",");
			
			double x = Double.valueOf(tokens[0]);
			double y = Double.valueOf(tokens[1]);
			
			verts[0][i] = new Vector2D(x, y);
		}
		
		return buildSet(verts);
	}

Mime
View raw message