GeneralPath / ArrayList -> Polygon

Hi,

is it possible to convert shapes drawn using GeneralPath to a polygon (java.awt.polygon)?

e.g.: I have this shape:

public Shape drawBird(){

path.moveTo(50, 50);

path.lineTo(70, 44);

path.curveTo(100, 10, 140, 80, 160, 80);

path.lineTo(190, 40);

path.lineTo(200, 56);

path.quadTo(100, 150, 70, 60);

path.closePath();

return path;

}

Is it possible to define a polygon with these coordinates (using polygon.addPoint())?

Furthermore, is it possible to define coordinates stored in an ArrayList as a polygon?

private List <Point2D>allPlayerCoordinates =new ArrayList<Point2D>();

Thanks a lot!

[892 byte] By [SFLa] at [2007-11-27 2:30:46]
# 1
to find out, try it out... seems logical enough, right ?
MaxxDmga at 2007-7-12 2:44:52 > top of Java-index,Desktop,Core GUI APIs...
# 2
> to find out, try it out... As a newbie I am interested whether it makes sense or whether it's a good idea to do it this way. That's why I am asking ;)Could I test 2 (or more) polygons for collision / intersection without using a bounding box?
SFLa at 2007-7-12 2:44:52 > top of Java-index,Desktop,Core GUI APIs...
# 3

It makes sense for straight segments, but not for curves and quads. To make these into polygons, you'll have to break them into segment approximation. Search the net for "curve approximation". Depending on the degree of precision, the resulting polygon will have much more points than the original path.

kirillga at 2007-7-12 2:44:52 > top of Java-index,Desktop,Core GUI APIs...
# 4
Shape s = ...FlatteningPathIterator fpi = new FlatteningPathIterator(s.getPathIterator(), 1.0);Now the fpi variable has only MOVE TO and LINE TO, there are no CURVE TO. The smaller the value of 1.0, the closer the lines will huge the pure curve.
rkippena at 2007-7-12 2:44:52 > top of Java-index,Desktop,Core GUI APIs...
# 5
> Shape s = ...> FlatteningPathIterator fpi = new> FlatteningPathIterator(s.getPathIterator(), 1.0);Thanks, this helped a lot :)
SFLa at 2007-7-12 2:44:52 > top of Java-index,Desktop,Core GUI APIs...