[Java] WInkelbrechnung(Dreieck)

georg_willi

Cadet 4th Year
Registriert
Juli 2004
Beiträge
110
Hallo. Ein Teil meines Programms soll dafür sorgen, dass mit Hilfe von 3 Seiten, die vorher eingegeben wurden, die Winkel des Dreiecks berechnet werden. Dazu hab ich den Kosinussatz benutzt. Es ist auch soweit alles in Ordnung, nur die Ausgabe stimmt nicht.
So siehts aus(bei mir sind die Seiten Arrays--> zahl[0]...zahl[2]):
Code:
                double cos_a= (zahl[0]* zahl[0])/((zahl[1]*zahl[1])+(zahl[2]*zahl[2])-2*zahl[1]*zahl[2]);
		double cos_alpha=Math.acos(cos_a);
				
		double cos_b= (zahl[1]* zahl[1])/((zahl[0]*zahl[0])+(zahl[2]*zahl[2])-2*zahl[0]*zahl[2]);
		double cos_betha=Math.acos(cos_b);
		
		double cos_g= (zahl[2]* zahl[2])/((zahl[0]*zahl[0])+(zahl[1]*zahl[1])-2*zahl[0]*zahl[1]);
		double cos_gamma=Math.acos(cos_g);
		
		System.out.println("Winkel alpha:  "+Math.toDegrees(cos_alpha));
		System.out.println("Winkel betha:  "+Math.toDegrees(cos_betha));
		System.out.println("Winkel gamma:  "+Math.toDegrees(cos_gamma));

Als Wert wird je "NaN" ausgeben : zahl wäre dem nach zu groß(glaub ich)

Danke im Vorraus:)
 
Zuletzt bearbeitet:
Cos Satz: c²=a²+b²-2ab*cosy
Dann wäre der Winkel: y = acos ((a²+b²-c²)/2ab)

cos_alpha = Math.acos( ((zahl[0]*zahl[0]+zahl[1]*zahl[1]-zahl[2]*zahl[2])/2/zahl[0]/zahl[1]))
 
es heißt dann aber

Dann wäre der Winkel: y = acos ((a²+b²-c²)/-2ab)

aber trotzdem danke, du hast mir meinen hauptfehler gezeigt:
ich dachte c²=a²+b²-2ab*cosy wären 2 faktoren --> (c²=a²+b²-2ab)*cosy
asche auf mein haupt...der kosinussatz...nee nee nee:D
 
nein: c²=a²+b²-2ab*cosy => c²--b²= -2ab*cosy => (c²--b²)/-2ab=cosy =>Minus kürzen: (a²+-c²)/2ab = cos y
 

Ähnliche Themen

Zurück
Oben