0

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

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 值)

4

2 回答 2

4

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

在 Wikipedia 上查找内圆中心的公式:

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

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

{ (x0+x1+x2)/3, (y0+y1+y2)/3 }
于 2013-02-22T01:55:06.190 回答
1

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

x = (x1 + x2 + x3) / 3
y = (y1 + y2 + y3) / 3
于 2013-02-22T01:54:42.943 回答