gpt4 book ai didi

java - 等边三角形中心坐标

转载 作者:行者123 更新时间:2023-12-01 17:25:50 24 4
gpt4 key购买 nike

我当前的三角形类如下所示:

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 = height/2 但这仅在底座水平时才有效(两个角具有相同的 y 值) )

最佳答案

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

查找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 }

关于java - 等边三角形中心坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15015518/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com