Java 判断两个多边形相交 Polygon intersect Polygon

1.先将多边形转换为area

2.两个area相交

 3.判断新生成的area是否为空

代码:

import java.awt.Polygon;
import java.awt.geom.Area;


Polygon p = new Polygon(new int[]{1,1,3,3},new int[]{0,1,1,0},4);
Polygon p1 = new Polygon(new int[]{0,0,2,2},new int[]{0,1,1,0},4);
Area area = new Area(p);
area.intersect(new Area(p1));
System.out.println(area.isEmpty());

   

你可能感兴趣的:(java)