资源简介
可以对简单多边形实现求并、交、差,复杂多边形之间的并、交、差
代码片段和文件信息
package srs.Geometry;
import java.util.ArrayList;
import java.util.List;
import srs.Geometry.SpatialOp.Line;
public class Difference {
public static List JoinRingPoints = new ArrayList();
static double EP=Math.pow(0.1 8);
static double p=0.0005;
/**两个多边形求差P-Q
* @param polysP
* @param polysQ
*/
public static IPolygon DifferenceResault(List> polysPList> polysQ){
//将两个多边形左边全部转换成3D格式polysP3D和polysQ3D
List> polysP3D = new ArrayList>();
List> polysQ3D = new ArrayList>();
List> Lpolys = new ArrayList>();
IPolygon polygon = new Polygon();
polysP3D = PolygonTo3D(polysP);
polysQ3D = PolygonTo3D(polysQ);
//求出两个多边形多个环的所有交点JoinRingPoints
for(int i=0;i< polysP.size();i++){
for(int j=0;j List list = new ArrayList();
list = InterPoints(polysP3D.get(i)polysQ3D.get(j));
if(list.size() != 0){
int h= list.size();
for(int l=0;l if(JoinRingPoints.size()==0){
JoinRingPoints.add(list.get(l));
}
else{
for(int k=0;k if(SpatialOp.Point_Equal(JoinRingPoints.get(k).Point() list.get(l).Point())==true){
JoinRingPoints.remove(list.get(l));
break;
}
}
JoinRingPoints.add(list.get(l));
}
}
}
}
}
if(JoinRingPoints.size()>1){
//循环几次就是几个环
for(;JoinRingPoints.size()>0;){
//遍历所有交点
int[] a = new int[4];//点在PQ中的位置
double b ;
List list = new ArrayList();
Lpolys.add(list);
list.add(JoinRingPoints.get(0));
a = LocationOnPQ(JoinRingPoints.get(0)polysP3DpolysQ3D);
Point3D p =polysP3D.get(a[0]).get(a[2]-1);
Point3D pp =polysP3D.get(a[0]).get(a[2]+1);
Point3D q = polysQ3D.get(a[1]).get(a[3]-1);
Point3D qq = polysQ3D.get(a[1]).get(a[3]+1);
b = getAngle(ppqqpq);
JoinRingPoints.remove(0);
if(b<=180){
list.add(polysQ3D.get(a[1]).get(a[3]+1));
JoinRingPoints.remove(polysQ3D.get(a[1]).get(a[3]+1));
}
else if(b>180)
{
list.add(polysP3D.get(a[0]).get(a[2]+1));
JoinRingPoints.remove(polysP3D.get(a[0]).get(a[2]+1));
}
for(;list.get(0)!=list.get(list.size()-1);)//不是出发点
{
//list里最后一个点y
Point3D y = list.get(list.size()-1);
if(y.Z()==1)//是交点
{
int[] aa = new int[4];
double bb;
aa = LocationOnPQ(ypolysP3DpolysQ3D);
bb = getAngle(polysP3D.get(aa[0]).get(aa[2]+1)polysQ3D.get(aa[1]).get(aa[3]+1)polysP3D.get(aa[0]).get(aa[2]-1)polysQ3D.get(aa[1]).get(aa[3]-1));
if(bb<=180)
{
list.add(polysQ3D.get(aa[1]).get(aa[3]+1));
JoinRingPoints.remove(y);
JoinRingPoints.remove(polysQ3D.get(aa[1]).get(aa[3]+1));
if(
评论
共有 条评论