概述
正如我在评论中所说。迭代轮廓路径,获得绕组并识别段起点。当你点击PathIterator.SEG_MOVETO构造一个java.awt.Path2D.Float并向其添加点数,直到你点击PathIterator.SEG_CLOSE。
这是我为你演示的一个例子
public static List getAreas(Area area) {
PathIterator iter = area.getPathIterator(null);
List areas = new ArrayList();
Path2D.Float poly = new Path2D.Float();
Point2D.Float start = null;
while(!iter.isDone()) {
float point[] = new float[2]; //x,y
int type = iter.currentSegment(point);
if(type == PathIterator.SEG_MOVETO) {
poly.moveTo(point[0], point[1]);
} else if(type == PathIterator.SEG_CLOSE) {
areas.add(new Area(poly));
poly.reset();
} else {
poly.lineTo(point[0],point[1]);
}
iter.next();
}
return areas;
}
public static void main(String[] args) {
Area a = new Area(new Polygon(new int[]{0,1,2}, new int[]{2,0,2}, 3));
Area b = new Area(new Polygon(new int[]{0,2,4}, new int[]{0,2,0}, 3));
b.subtract(a);
for(Area ar : getAreas(b)) {
PathIterator it = ar.getPathIterator(null);
System.out.println("New Area");
while(!it.isDone()) {
float vals[] = new float[2];
int type = it.currentSegment(vals);
System.out.print(" " + "[" + vals[0] + "," + vals[1] +"]");
it.next();
}
System.out.println();
}
}
最后
以上就是冷艳期待为你收集整理的java.awt.geom多边形_java.awt.geom.Area减法后返回多个部分?的全部内容,希望文章能够帮你解决java.awt.geom多边形_java.awt.geom.Area减法后返回多个部分?所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复