java area (outline) to polygon / array (x, y)

i wrote a program which traces an image’s outline. therefore i used java area to use methods such as subtract, add, … well, it wasn’t that difficult to write an collision detection script but the matter is that i don’t have any idea how to get an outline polygon (area to outlinepoly) -> x1,y1; x2,y2 …
is there any help? or shld i write my own subtract method / area script???
:o
ty
:slight_smile:

Could you use Area.getPathIterator(null) and then iterate over the points using pathIterator.next()?

Your method of making a polygon from an image sounds very cool. How did you go about it? 8)

By the way, Kev Glass has some great polygon constructive area geometry methods in his Slick library (http://slick.cokeandcode.com/) if you find that the Area class is too slow (org.newdawn.slick.geom.GeomUtil)

Also, I made a polygon class that’s fairly flexible which can be drawn by java2D (astarpathfinder.geom.KPolygon in http://keithphw.freehostia.com/LineOfSight/src.zip).

I hope that helps :slight_smile:

yepp, thank u v much. it’s a simple algorithm. after defining your bg-colour (white or transparent) an observer is following the bounding-rect ( top_left to bottom_left, …), checks for the 1st pix != bg-col (row/column) and stores the pos in an area. i repeat that cycle 4 times, varying the starting corner. after that i get the intersection of all areas :). (i also used a contrast filter) works fine for simple surfaces + it is quite fast because it is linear
linked to my sprite-class i get a dynamic collision model (each frame gets it’s mask).

working 8)
ty :smiley:

    	mask_tmp = new Polygon();
    	
    	PathIterator path = a.getPathIterator(null);
        while (!path.isDone()) {
            toPolygon(path);
            path.next();}

    	return mask_tmp;}
	
	  private static void toPolygon(PathIterator p_path) {
		    double[] point = new double[2];
		    if(p_path.currentSegment(point) != PathIterator.SEG_CLOSE)
		    	mask_tmp.addPoint((int) point[0], (int) point[1]);}