0
n角形の点の間の角度を計算しようとしています。 xとy座標を保持する2つの配列があります。私はP13でエラーが発生し続けているので、理由を理解できません。誰かが理由を知っていますか?n角の角度を計算する(プラスの比較)
public class Ugao {
public static int nizovi(double[]a , double[]b , double alfa) {
int BrStr = 0;
for (int i = 0; i < b.length; i++) {
double P12,P13, P23;
P12 = duzina(a[i+1], b[i+1], a[i], b[i]);
P13 = duzina(a[i+1], b[i+1], a[i+2], b[i+2]); // pisemo prvo i+1 jer je to vertex tacka, ona koja je u centru ugla, zato nije od i
P23 = duzina(a[i], b[i], a[i+2], b[i+2]);
double x = ugao(P12, P13, P23);
if(x > alfa) {
System.out.print("Stranica : " + "(" + a[i] + "," + b[i] + ")" + "(" + a[i+1] + "," + b[i+1] + ")" + " & ");
System.out.println("(" + a[i+1] + "," + b[i+1] + ")" + "(" + a[i+2] + "," + b[i+2] + ")");
System.out.println();
BrStr++;
}
}
return BrStr;
}
public static double ugao (double P12, double P13, double P23) {
return Math.acos((Math.pow(P12, 2) + Math.pow(P13, 2) - Math.pow(P23, 2))/(2 * P12 * P13));
}
public static double duzina (double vertexX1, double vertexY1, double x2, double y2) {
return Math.sqrt(Math.pow((vertexX1-x2),2)+ Math.pow((vertexY1-y2), 2));
}
public static void main(String[] args) {
// TODO Auto-generated method stub
double a[] = {12,25,3};
double b[] = {11,20,5};
nizovi(a, b, 45);
}
}
訂正と提案!それはすてきな修正です! :) – Echelonica