{
MyPoint goodPoint=null;
for(int i=1;i<=pointSet.size();i++) { MyPoint activePoint=pointSet.get(i);
if(this.isOnLeft(activePoint, pointSet))//判断当前活动点是不是在直线的左边 { //在直线左边 double minCos=this.getCos(activePoint, pointSet); int good=i; for(int j=i+1;j<=pointSet.size();j++)
{//对当前活动边的左边点进行空圆准则检验
if(this.isOnLeft(pointSet.get(j), pointSet))//判断当前活动点是不是 { double cos=this.getCos(pointSet.get(j), pointSet); if(cos goodPoint=pointSet.get(good); /* * 下面是生成边后的后期处理 */ newEdge1=new 在直线的左边 //生成的第一边 MyEdge MyEdge(this.getBeginPoint(pointSet),goodPoint); newEdge1.addUseCount(); if(edgeSet.containsValue(newEdge1)) { MyEdge.count--; for(int k=1;k<=edgeSet.size();k++) { if(edgeSet.get(k).equals(newEdge1)) { edgeSet.get(k).addUseCount(); break; } } }else edgeSet.put(newEdge1.id, newEdge1); newEdge2=new //生成的第二边 MyEdge MyEdge(goodPoint,this.getEndPoint(pointSet)); newEdge2.addUseCount(); if(edgeSet.containsValue(newEdge2)) { MyEdge.count--; for(int k=1;k<=edgeSet.size();k++) { if(edgeSet.get(k).equals(newEdge2)) { edgeSet.get(k).addUseCount(); break; } } }else edgeSet.put(newEdge2.id, newEdge2); //对第三边进行处理 this.addUseCount(); this.turnBeginAndEnd(); //生成三角形,并加入到三角形集合中 MyTriangle newTriangle=new MyTriangle(this.getBeginPoint(pointSet),goodPoint,this.getEndPoint(pointSet),edgeSet); triangleSet.put(newTriangle.id, newTriangle); break; } } return goodPoint; } /* * 此方法是将某一点与当前边的顶点角的余弦值返回 */ private double getCos(MyPoint p,Map } } import java.util.*; import java.io.*; public class MyPoint { public static int count=0; public int id; public int x; public int y; private String info; public MyPoint(int x,int y) { this.id=++count; this.x=x; this.y=y; } public void setInfo(String info) { this.info=info; } public String getInfo() { return this.info; } public double distance(int x,int y) { int tempx=(this.x-x)*(this.x-x); int tempy=(this.y-y)*(this.y-y); return Math.sqrt((tempx+tempy)); } public double distance(MyPoint p) { int tempx=(this.x-p.x)*(this.x-p.x); int tempy=(this.y-p.y)*(this.y-p.y); return Math.sqrt((tempx+tempy)); } /* * 下面这个方法是找寻主叫点在点集中与之最近的点 * 返回的是与之最近点的引用 */ public MyPoint getMinDistancePoint(Map *下面的方法是将点集中的点全部输出到文件中 */ public static boolean savePoints(Map * 下面的方法是将文件中的点加载到内存中 */ public static boolean readPoints(Map { boolean flag=false; File file=new File(filename); try { FileInputStream in=new FileInputStream(file); Scanner fromfile=new Scanner(in); while(fromfile.hasNextInt()) { fromfile.nextInt(); MyPoint point=new MyPoint(fromfile.nextInt(),fromfile.nextInt()); pointSet.put(point.id, point); } flag=true; in.close(); }catch(IOException e) { return flag; } return flag; } } import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.util.*; public class MyTin extends JFrame { public static void main(String[] agrs) { MyTin tin=new MyTin(\三角网的生成\ } private MyPanel show; private JButton begin; public MyTin(String title)