高分求高人!

Botroskey 2012-05-25 04:49:18
用Java编写一个应用程序,该应用程序实现:
在二维平面,有一组随机点组成的三角形,画出三角形,并求出各个三角形的外接圆圆心,
将三角形的圆心存入数组,并画出外接圆心组成的三角形同时将前面画出的三角形消去
...全文
125 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
Botroskey 2012-05-26
  • 打赏
  • 举报
回复
那个还差数据结构的问题[Quote=引用 5 楼 的回复:]

代码都写出来了,,,还问人怎么做干嘛???你是没有思路,还是啥。引用 4 楼 的回复:
不是啊,是怎么做的问题

引用 3 楼 的回复:

是代码有问题还是?

贴个错误啊?
[/Quote]
香蕉猪 2012-05-26
  • 打赏
  • 举报
回复
代码都写出来了,,,还问人怎么做干嘛???你是没有思路,还是啥。[Quote=引用 4 楼 的回复:]
不是啊,是怎么做的问题

引用 3 楼 的回复:

是代码有问题还是?

贴个错误啊?
[/Quote]
Botroskey 2012-05-25
  • 打赏
  • 举报
回复
不是啊,是怎么做的问题[Quote=引用 3 楼 的回复:]

是代码有问题还是?

贴个错误啊?
[/Quote]
yuppy 2012-05-25
  • 打赏
  • 举报
回复
是代码有问题还是?

贴个错误啊?
Botroskey 2012-05-25
  • 打赏
  • 举报
回复
=======================画三角形的类==================================
public class TriangleDrawer extends JPanel {

private static final long serialVersionUID = 1L;

private Triangle triangle;

public TriangleDrawer() {

triangle = new Triangle(new Point2D.Double(100, 100), new Point2D.Double(207, 130),

new Point2D.Double(220, 200));
}


@Override

protected void paintComponent(Graphics g) {

super.paintComponent(g);

Graphics2D g2d = (Graphics2D) g;

g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

// 绘制三角形
drawLine(g, triangle.getP1(), triangle.getP2());
drawLine(g, triangle.getP2(), triangle.getP3());
drawLine(g, triangle.getP3(), triangle.getP1());
}

protected void drawLine(Graphics g, Point2D.Double startPoint, Point2D.Double endPoint) {

g.drawLine((int) startPoint.x, (int) startPoint.y, (int) endPoint.x, (int) endPoint.y);
}

protected void drawCircle(Graphics g, Point2D.Double center, double radius) {
g.drawOval((int) (center.x - radius), (int) (center.y - radius), (int) (2 * radius),
(int) (2 * radius));
}

private static void createGUIAndShow() {
JFrame frame = new JFrame("三角形");
JPanel contentPane = new TriangleDrawer();
frame.setContentPane(contentPane);

Dimension ss = Toolkit.getDefaultToolkit().getScreenSize();

int w = 500;

int h = 500;

int x = (ss.width - w) / 2;

int y = (ss.height - h) / 2;

x = x > 0 ? x : 0;

y = y > 0 ? y : 0;

frame.setBounds(x, y, w, h);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setVisible(true);

}

public static void main(String[] args) {

SwingUtilities.invokeLater(new Runnable() {

@Override

public void run() {
createGUIAndShow();
}
});
}
}
Botroskey 2012-05-25
  • 打赏
  • 举报
回复
========================三角形的外接圆心==========================
public class Triangle {
// 三角形的三个顶点
private Point2D.Double p1;
private Point2D.Double p2;
private Point2D.Double p3;

public Triangle(Point2D.Double p1, Point2D.Double p2, Point2D.Double p3) {
this.p1 = p1;
this.p2 = p2;
this.p3 = p3;

dis12 = distenceOfPoints(p1, p2);
dis23 = distenceOfPoints(p2, p3);
dis31 = distenceOfPoints(p3, p1);
}
// 两点之间的距离
public static double distenceOfPoints(Point2D.Double p1, Point2D.Double p2) {
return Math.sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y));
}
// 外切圆圆心

public Point2D.Double outerCenter() {
double x1 = p1.x;
double x2 = p2.x;
double x3 = p3.x;
double y1 = p1.y;
double y2 = p2.y;
double y3 = p3.y;

double x = ((y2 - y1) * (y3 * y3 - y1 * y1 + x3 * x3 - x1 * x1) - (y3 - y1)

* (y2 * y2 - y1 * y1 + x2 * x2 - x1 * x1))

/ (2 * (x3 - x1) * (y2 - y1) - 2 * ((x2 - x1) * (y3 - y1)));

double y = ((x2 - x1) * (x3 * x3 - x1 * x1 + y3 * y3 - y1 * y1) - (x3 - x1)

* (x2 * x2 - x1 * x1 + y2 * y2 - y1 * y1))

/ (2 * (y3 - y1) * (x2 - x1) - 2 * ((y2 - y1) * (x3 - x1)));

return new Point2D.Double(x, y);

}

58,454

社区成员

发帖
与我相关
我的任务
社区描述
Java Eclipse
社区管理员
  • Eclipse
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧