• 大小: 296KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-07-11
  • 语言: 其他
  • 标签: 凸包问题  

资源简介

哈工大算法实验一,凸包问题 1.基于枚举方法的凸包求解算法 2.实现基于Graham-Scan的凸包求解算法 3.实现基于分治思想的凸包求解算法 4.界面图,可以用鼠标随便点,然后用这些点求出凸包并在界面上画出凸包源代码和实验报告!均为自己所做,正确运行。报告中还有用Excel表分析了算法的性能

资源截图

代码片段和文件信息

package hit.shuai.suanfa01;

import hit.shuai.suanfa01.grahamscan.GrahamScan;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.geom.Ellipse2D;
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.linkedList;
import java.util.List;

import javax.swing.JButton;
import javax.swing.Jframe;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;



public class ConvexHull extends Jframe implements ActionListener {

JButton jButton = new JButton(“开始计算凸包“);
PointPanel pointPanel = new PointPanel();
static ConvexHull convexHull;
GrahamScan gs = new GrahamScan();

public ConvexHull() {
JPanel contentPanel = (JPanel) getContentPane();
contentPanel.setLayout(new BorderLayout());
contentPanel.setBorder(new EmptyBorder(10 10 10 10));
setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE);
contentPanel.add(pointPanel BorderLayout.CENTER);
JPanel p2 = new JPanel();
p2.add(jButton BorderLayout.NORTH);
jButton.addActionListener(this);
contentPanel.add(p2 BorderLayout.SOUTH);
setSize(400 400);
setLocation(200 200);
setVisible(true);
}

public static void main(String[] args) {

convexHull = new ConvexHull();
}

@Override
public void actionPerformed(ActionEvent arg0) {
List pointList = convexHull.pointPanel.getPointList();
Ellipse2D A;
//System.out.println(“123“ + pointList.size());
for (int i = 0; i < pointList.size(); i++) {
A = (Ellipse2D) pointList.get(i);
hit.shuai.suanfa01.Point p = new hit.shuai.suanfa01.Point(A.getX() A.getY());
gs.groupAdd(p);
}
gs.startGrahamScan();
linkedList points = gs.getRes();
int n = points.size()-1;
for(int i = 0 ; i < n ; i++)
{
pointPanel.getGraphics().drawLine((int)points.get(i).x (int)points.get(i).y (int)points.get(i+1).x (int)points.get(i+1).y);
}
pointPanel.getGraphics().drawLine((int)points.get(n).x (int)points.get(n).y (int)points.get(0).x (int)points.get(0).y);

}

class PointPanel extends JPanel {
List pointList;
Color selectedColor;
Ellipse2D selectedPoint;

public PointPanel() {
pointList = new ArrayList();
selectedColor = Color.red;
addMouseListener(new PointLocater(this));
setBackground(Color.white);

}

protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING
RenderingHints.VALUE_ANTIALIAS_ON);
Ellipse2D e;
Color color;
for (int j = 0; j < pointList.size(); j++) {
e = (Ellipse2D) pointList.get(j);
if (e == selectedPoint)
color = select

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2014-12-25 11:33  suanfa01\
     文件         307  2013-11-18 14:28  suanfa01\.classpath
     文件         384  2013-11-18 14:28  suanfa01\.project
     目录           0  2014-12-25 11:33  suanfa01\.settings\
     文件         144  2014-12-09 14:58  suanfa01\.settings\org.eclipse.core.resources.prefs
     文件          83  2014-12-07 17:24  suanfa01\.settings\org.eclipse.core.runtime.prefs
     文件         629  2013-11-18 14:28  suanfa01\.settings\org.eclipse.jdt.core.prefs
     目录           0  2014-12-25 11:33  suanfa01\bin\
     目录           0  2014-12-25 11:33  suanfa01\bin\hit\
     目录           0  2014-12-25 11:33  suanfa01\bin\hit\shuai\
     目录           0  2014-12-25 11:33  suanfa01\bin\hit\shuai\suanfa01\
     文件        1692  2014-12-20 11:59  suanfa01\bin\hit\shuai\suanfa01\ConvexHull$PointLocater.class
     文件        2715  2014-12-20 11:59  suanfa01\bin\hit\shuai\suanfa01\ConvexHull$PointPanel.class
     文件        3269  2014-12-20 11:59  suanfa01\bin\hit\shuai\suanfa01\ConvexHull.class
     目录           0  2014-12-25 11:33  suanfa01\bin\hit\shuai\suanfa01\fenzhi\
     文件        1201  2014-12-20 11:59  suanfa01\bin\hit\shuai\suanfa01\fenzhi\Line.class
     文件        1221  2014-12-20 11:59  suanfa01\bin\hit\shuai\suanfa01\fenzhi\QuickTuBao$1.class
     文件         613  2014-12-20 11:59  suanfa01\bin\hit\shuai\suanfa01\fenzhi\QuickTuBao$FPoint.class
     文件        4341  2014-12-20 11:59  suanfa01\bin\hit\shuai\suanfa01\fenzhi\QuickTuBao.class
     目录           0  2014-12-25 11:33  suanfa01\bin\hit\shuai\suanfa01\grahamscan\
     文件        4093  2014-12-20 11:59  suanfa01\bin\hit\shuai\suanfa01\grahamscan\GrahamScan.class
     文件        1356  2014-12-20 11:59  suanfa01\bin\hit\shuai\suanfa01\grahamscan\SPoint.class
     文件        1642  2014-12-20 11:59  suanfa01\bin\hit\shuai\suanfa01\Launcher.class
     目录           0  2014-12-25 11:33  suanfa01\bin\hit\shuai\suanfa01\meiju\
     文件        2867  2014-12-20 11:59  suanfa01\bin\hit\shuai\suanfa01\meiju\Meiju.class
     文件        1267  2014-12-20 11:59  suanfa01\bin\hit\shuai\suanfa01\Point.class
     文件        1195  2014-12-20 11:59  suanfa01\bin\hit\shuai\suanfa01\PointFactory.class
     目录           0  2014-12-25 11:33  suanfa01\src\
     目录           0  2014-12-25 11:33  suanfa01\src\hit\
     目录           0  2014-12-25 11:33  suanfa01\src\hit\shuai\
     目录           0  2014-12-25 11:33  suanfa01\src\hit\shuai\suanfa01\
............此处省略13个文件信息

评论

共有 条评论