C# :: Aufgabe #261 :: Lösung #2
5 Lösungen
#261
Alle Winkel von einem Dreieck ausrechnen...
Fortgeschrittener - C#
von maxi72501
- 06.05.2019 um 15:01 Uhr
Gegeben sind alle Koordinaten. Die Punkte A und B gibt der Benutzer ein und die C Koordinate ist der Koordinaten Ursprung (0, 0).
Anhand der Seiten soll der Flächeninhalt und alle Winkel berechnet werden.
Anhand der Seiten soll der Flächeninhalt und alle Winkel berechnet werden.
#2
von suppengruen (200 Punkte)
- 14.05.2019 um 14:18 Uhr
C#-Code
using System; namespace DreieckCalc { /* Gegeben sind alle Koordinaten.Die Punkte A und B gibt der Benutzer ein und die C Koordinate ist der Koordinaten Ursprung (0, 0). Anhand der Seiten soll der Flächeninhalt und alle Winkel berechnet werden. */ class Program { static Double[] a = new Double[2]; static Double[] b = new Double[2]; static Double[] c = { 0, 0 }; static Double sA, sB, sC, fi, alpha, beta, gamma; static void Main(string[] args) { Eingeben(); Rechnen(); Ausgeben(); } static void Eingeben() { int kompos; string koordhelp; //A Console.WriteLine("Gib die Koordianten von A ein!\nFormat: x,y"); koordhelp = Console.ReadLine(); kompos = koordhelp.IndexOf(','); if(kompos == -1) { Console.Clear(); Console.WriteLine("Komma konnte nicht gefunden werden!"); return; } a[0] = Convert.ToDouble(koordhelp.Substring(0, kompos)); a[1] = Convert.ToDouble(koordhelp.Substring(kompos + 1)); //B Console.WriteLine("Gib die Koordianten von B ein!\nFormat: x,y"); koordhelp = Console.ReadLine(); kompos = koordhelp.IndexOf(','); if (kompos == -1) { Console.Clear(); Console.WriteLine("Komma konnte nicht gefunden werden!"); return; } b[0] = Convert.ToDouble(koordhelp.Substring(0, kompos)); b[1] = Convert.ToDouble(koordhelp.Substring(kompos + 1)); } static void Rechnen() { //Seite b sB = Math.Sqrt((Math.Pow(a[0],2) + Math.Pow(a[1],2))); //Seite a sA = Math.Sqrt((Math.Pow(b[0], 2) + Math.Pow(b[1], 2))); //Seite c double helpc1; double helpc2; helpc1 = a[0] - b[0]; helpc2 = a[1] - b[1]; if(helpc1 < 0 ) { helpc1 = helpc1 * (-1); } if (helpc2 < 0) { helpc2 = helpc2 * (-1); } sC = Math.Sqrt(Math.Pow(helpc1, 2) + Math.Pow(helpc2, 2)); //Flächeninhalt fi = Math.Sqrt((sA + sB + sC)*(sA + sB - sC)*(sB + sC - sA)*(sC + sA - sB)) / 4; //Winkel alpha = Math.Acos((Math.Pow(sB, 2) + Math.Pow(sC, 2) - Math.Pow(sA, 2)) / (2 * sB * sC)); beta = Math.Acos((Math.Pow(sA, 2) + Math.Pow(sC, 2) - Math.Pow(sB, 2)) / (2 * sA * sC)); gamma = Math.Acos((Math.Pow(sA, 2) + Math.Pow(sB, 2) - Math.Pow(sC, 2)) / (2 * sA * sB)); alpha = RadUmrechner(alpha); beta = RadUmrechner(beta); gamma = RadUmrechner(gamma); } static double RadUmrechner(double rad) { double deg = 0.0; deg = 180 / Math.PI * rad; return deg; } static void Ausgeben() { Console.Clear(); Console.WriteLine("Das Ergebnis ist..."); Console.WriteLine("Flächeninhalt: {0}cm²\nAlpha: {1}°\nBeta: {2}°\nGamma:{3}°",fi,alpha,beta,gamma); Console.ReadLine(); } } }
Kommentare:
Für diese Lösung gibt es noch keinen Kommentar
Seite 1 von 0
1