我试图创建一个程序,在该程序中创建一个圆圈中的三个随机点,并导致创建一个内切三角形。然而,我得到的角度都搞砸了
这是我的代码:
public static void main(String[] args) {
double r = 40.0;
double angle1 = Math.random()* (2 * Math.PI);
double angle2 = Math.random()* (2 * Math.PI);
double angle3 = Math.random()* (2 * Math.PI);
double x_1 = r * Math.cos(angle1);
double y_1 = r * Math.sin(angle1);
double x_2 = r * Math.cos(angle2);
double y_2 = r * Math.sin(angle2);
double x_3 = r * Math.cos(angle3);
double y_3 = r * Math.sin(angle3);
System.out.println("The coordinates of the three points are:
(" + x_1 + ", " + y_1 + ")
(" + x_2 + ", " + y_2 + ")
(" + x_3 + ", " + y_3 + ")");
//Get length of each side
double distanceFrom1To2 = Math.sqrt(Math.pow(x_2 - x_1, 2) +
Math.pow(y_2 - y_1, 2));
double distanceFrom2To3 = Math.sqrt(Math.pow(x_3 - x_2, 2) +
Math.pow(y_3 - y_2, 2));
double distanceFrom3To1 = Math.sqrt(Math.pow(x_1 - x_3, 2) +
Math.pow(y_1 - y_3, 2));
//Get angles ***
double triangleAngle1 = Math.atan(distanceFrom1To2 / distanceFrom2To3);
double triangleAngle2 = Math.atan(distanceFrom2To3 / distanceFrom3To1);
double triangleAngle3 = Math.atan(distanceFrom3To1 / distanceFrom1To2);
System.out.println("The three angles are " + triangleAngle1 + " " +
triangleAngle2 + " " + triangleAngle3);
System.out.println(triangleAngle1 + triangleAngle2 + triangleAngle3);
}
我绝对知道获得角度的方法搞砸了。以下是我的程序示例:
The coordinates of the three points are: (5.224534224725408,
-39.65733528787168) (-29.696946087404676, 26.79722733944279)
(32.70889681040468, -23.02451018906371)
The three angles are 0.7545364726122026 1.18830825410364
0.40435068059871415
Total angle sum: 2.347195407314557
所有角度加起来都大于Pi / 2弧度。我已经考虑了正弦定律,但你必须至少知道一个角度......
答案 0 :(得分:0)
想出来
这是固定代码:
function runGetList(filename) {
var p = new Promise(function(resolve, reject) {
// do stuff to get jsonMDBList
resolve(jsonMDBList)
}};
return p;
}
function getAllLists() {
var mdbListAll = runGetList('GetListMDBs.py'); // returns promise 1
mdbListAll.then(function(data) { // runs when promise 1 resolves
console.log("list mdbs: " + data);
mdbListTbl = runGetList('GetTable.py'); // returns promise 2
return mdbListTbl
}).then(function(data) { // runs when promise 2 resolves
console.log("table mdbs: " + data);
});
}
我改变它以使用余弦定律。