【问题标题】:Coordinates of centre, equilateral triangle中心坐标,等边三角形
【发布时间】:2013-02-07 13:25:50
【问题描述】:

我当前的三角形类看起来像:

public class TriangleEquilateral {
    private Point cornerA;
    private Point cornerB;
    private Point cornerC;
    private double x1 = 0;
    private double y1 = 0;
    private double x2 = 10;
    private double y2 = 0;
    private double x3 = 5;
    private double y3 = Math.sqrt(75);

    public TriangleEquilateral(){
        cornerA = new Point(x1,y1);
        cornerB = new Point(x2,y2);
        cornerC = new Point(x3,y3);
    }

    public TriangleEquilateral(double X1,double Y1,double X2,double Y2,double X3,double Y3){
        x1 = X1;
        y1 = Y1;
        x2 = X2;
        y2 = Y2;
        x3 = X3;
        y3 = Y3;

        cornerA = new Point(X1,Y1);
        cornerB = new Point(X2,Y2);
        cornerC = new Point(X3,Y3);
    }

    public boolean isEquilateral(){
        double lengthAB = Math.sqrt(Math.pow(x1-x2,2) + Math.pow(y1-y2,2));
        double lengthBC = Math.sqrt(Math.pow(x2-x3,2) + Math.pow(y2-y3,2));
        double lengthCA = Math.sqrt(Math.pow(x3-x1,2) + Math.pow(y3-y1,2));

        boolean isEquilateral = false;
        if(lengthAB == lengthBC && lengthBC == lengthCA && lengthCA == lengthAB){
            isEquilateral = true;
        }
        System.out.println(lengthAB);
        System.out.println(lengthBC);
        System.out.println(lengthCA);
        return isEquilateral;
    }

    public double sideLength(){
        double sL = 0;
        if(this.isEquilateral() == true){
            sL = Math.sqrt(Math.pow(x1-x2,2) + Math.pow(y1-y2,2));
        }
        return sL;
    }

如何确定等边三角形的中点坐标?我知道中点是 x = (base/2), y = heigth/2 但这仅在基础水平时才有效(两个角具有相同的 y 值)

【问题讨论】:

  • 这不是Java 甚至不是编程问题,而是数学 问题。你看过数学网站或维基百科吗?你试过在纸上解决这个问题吗?

标签: java implementation


【解决方案1】:

对于等边三角形,三角形的圆心坐标与其内圆的圆心坐标相同。

查找the formula for the incircle's center on Wikipedia

{ (aXa+bXb+cXc)/(a+b+c), (aYa+bYb+cYc)/(a+b+c) }

由于a = b = c,很容易看出等边三角形的中心坐标很简单

{ (x0+x1+x2)/3, (y0+y1+y2)/3 }

【讨论】:

    【解决方案2】:

    这更像是一道数学题,而不是一道 java 题。无论如何,要找到重心:

    x = (x1 + x2 + x3) / 3
    y = (y1 + y2 + y3) / 3
    

    【讨论】:

      猜你喜欢
      • 2013-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-29
      • 2023-01-30
      • 1970-01-01
      • 1970-01-01
      • 2016-07-30
      相关资源
      最近更新 更多