77范文网 - 专业文章范例文档资料分享平台

基于狄洛尼三角网生成算法的源代码(3)

来源:网络收集 时间:2019-03-22 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:或QQ: 处理(尽可能给您提供完整文档),感谢您的支持与谅解。点击这里给我发消息

{ super(title); this.setSize(500, 580); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.getContentPane().setLayout(null); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.show=new MyPanel(); this.show.setBounds(0,0,this.getWidth(),this.getHeight()-80); this.begin=new JButton(\开始绘制\ this.begin.addActionListener(new MyButtonMonitor()); this.begin.setBounds(this.getWidth()/2-70, this.getHeight()-75,100,30); this.getContentPane().add(show); this.getContentPane().add(begin); //this.pack(); this.setVisible(true); }

public class MyPanel extends JPanel { public HashMap pointSet; public HashMap edgeSet; public HashMap triangleSet; public MyPanel() { this.setBackground(Color.LIGHT_GRAY); this.pointSet=new HashMap(); this.edgeSet=new HashMap(); this.triangleSet=new HashMap(); this.addMouseListener(new MyMouseMonitor()); } /* * 总的绘制方法 */ public void paint(Graphics g) { Color c=g.getColor();

g.setColor(Color.LIGHT_GRAY); g.fillRect(0, 0, 500, 500); g.setColor(Color.red); for(int i=1;i<=this.pointSet.size();i++) { g.fillOval(this.pointSet.get(i).x-2,this.pointSet.get(i).y-2,5,5); } if(!edgeSet.isEmpty()) { for(int i=1;i<=this.edgeSet.size();i++) { this.edgeSet.get(i).draw(g, pointSet); } } }

class MyMouseMonitor implements MouseListener { public void mouseClicked(MouseEvent e) { Point temp=e.getPoint(); MyPoint p=new MyPoint(temp.x,temp.y); pointSet.put(p.id,p); repaint(); } public void mousePressed(MouseEvent e) { } public void mouseReleased(MouseEvent e) { } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) {

} } }

class MyButtonMonitor implements ActionListener { HashMap pointSet=MyTin.this.show.pointSet; HashMap edgeSet=MyTin.this.show.edgeSet; HashMap triangleSet=MyTin.this.show.triangleSet; public void actionPerformed(ActionEvent e) { /* * 将点集中的点全部输出到文件中 */ MyPoint.savePoints(pointSet); //MyPoint.readPoints(pointSet, \ /*

* 点击“开始绘制”按钮后就会开始绘制

* 这里假定以点集中的第一个点为初始点进行绘制 */

MyPoint firstPoint=pointSet.get(1);

MyPoint secondPoint=firstPoint.getMinDistancePoint(pointSet);//找距初始点最近的点 MyEdge firstEdge=new MyEdge(firstPoint,secondPoint);//生成的第一个边 edgeSet.put(firstEdge.id, firstEdge);//将第一个边加入到边集中 MyTin.this.show.repaint(); int i=1; while(!edgeSet.isEmpty()) { MyEdge activeEdge=null; for( ;i<=edgeSet.size();i++) { activeEdge=edgeSet.get(i); if(activeEdge.getUseCount()<2) break; } if(i>edgeSet.size())break; //这是采用外接圆的方法找最优点 // MyPoint goodPoint=activeEdge.findGoodPointByCircle(pointSet, edgeSet, triangleSet); //这是采用余弦值的方法找最优点 MyPoint goodPoint=activeEdge.findGoodPointByAngle(pointSet, edgeSet,

triangleSet); if(goodPoint==null) activeEdge.addUseCount(); } MyTin.this.show.repaint(); } }

}import java.util.*; import java.awt.*;

public class MyTriangle { public static int count=0; public int id;

private int[] pID;//记录三角形中的点,按顺时针顺序排列 private int[] eID;//记录三角形中的边,按顺时针顺序排列 /*

* 下面这个构造方法是简单三角形构造法,其中没有边的信息 * 可以用它来做判断

* 建议最后生成的三角形不要用此构造方法 */

public MyTriangle(int p1ID,int p2ID,int p3ID) { this.pID=new int[3]; this.pID[0]=p1ID; this.pID[1]=p2ID; this.pID[2]=p3ID; } /*

* 注意此构造方法中的三点要满足顺时针的顺序 */

public MyTriangle(MyPoint p1,MyPoint p2,MyPoint p3,Map edgeSet) { this.id=++count; this.pID=new int[3]; this.pID[0]=p1.id; this.pID[1]=p2.id; this.pID[2]=p3.id; this.eID=new int[3]; this.eID[0]=MyEdge.getEdge(p1, p2, edgeSet).id; this.eID[1]=MyEdge.getEdge(p2, p3, edgeSet).id; this.eID[2]=MyEdge.getEdge(p3, p1, edgeSet).id; } /*

*此构造方法也是根据点来确定三角形

*但是传入的点是按照顺时针的顺序传入点的ID号 */

public MyTriangle(int p1ID,int p2ID,int p3ID,Map edgeSet) { this.id=++count; this.pID=new int[3]; this.pID[0]=p1ID; this.pID[1]=p2ID; this.pID[2]=p3ID; this.eID=new int[3]; this.eID[0]=MyEdge.getEdge(p1ID, p2ID, edgeSet).id; this.eID[1]=MyEdge.getEdge(p2ID, p3ID, edgeSet).id; this.eID[2]=MyEdge.getEdge(p3ID, p1ID, edgeSet).id; } /*

* 下面这个构造方法是按照边对象来构造三角形的 * 注意,边的顺序也要是按照顺时针的顺序进入 */ public MyTriangle(MyEdge e1,MyEdge e2,MyEdge e3,Map pointSet) { this.id=++count; this.pID=new int[3]; this.pID[0]=e1.getBeginPoint(pointSet).id; this.pID[1]=e2.getBeginPoint(pointSet).id; this.pID[2]=e3.getBeginPoint(pointSet).id; this.eID=new int[3]; this.eID[0]=e1.id; this.eID[1]=e2.id; this.eID[2]=e3.id; } /* * */ public MyTriangle(int e1ID,int e2ID,int e3ID,Map edgeSet,Map pointSet) { this.id=++count; this.pID=new int[3]; this.pID[0]=edgeSet.get(e1ID).getBeginPoint(pointSet).id; this.pID[1]=edgeSet.get(e2ID).getBeginPoint(pointSet).id; this.pID[2]=edgeSet.get(e3ID).getBeginPoint(pointSet).id; this.eID=new int[3]; this.eID[0]=e1ID;

百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库基于狄洛尼三角网生成算法的源代码(3)在线全文阅读。

基于狄洛尼三角网生成算法的源代码(3).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印 下载失败或者文档不完整,请联系客服人员解决!
本文链接:https://www.77cn.com.cn/wenku/zonghe/536611.html(转载请注明文章来源)
Copyright © 2008-2022 免费范文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ: 邮箱:tiandhx2@hotmail.com
苏ICP备16052595号-18
× 注册会员免费下载(下载后可以自由复制和排版)
注册会员下载
全站内容免费自由复制
注册会员下载
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: