C# :: Aufgabe #261 :: Lösung #4

5 Lösungen Lösungen öffentlich
#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.
#4
vote_ok
von bebbe80 (300 Punkte) - 22.06.2019 um 19:39 Uhr
Quellcode ausblenden C#-Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Trainb
{
    class Program
    {
        public static double Seitenlaenge(double x1, double y1, double x2, double y2)
        {
           double seite =  Math.Sqrt(Math.Pow((x1 - x2), 2) + Math.Pow((y1 - y2), 2));
            return seite;
        }
        public static double Winkel(double hypothenuse, double kathetea, double katheteb)
        {
            double winkel = Math.Acos((Math.Pow(hypothenuse, 2) - Math.Pow(kathetea, 2) - Math.Pow(katheteb, 2)) / (-2 * kathetea * katheteb)) * 180 / Math.PI;
            return winkel;
        }
        public static double Flaeche(double a, double b, double c)
        {
            double s = (a + b + c) / 2.0;
            double flaeche = Math.Sqrt(s * (s - a) * (s - b) * (s - c));
            return flaeche;
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Geben sie die erste x-Koordinate ein");
            double x1 = double.Parse(Console.ReadLine());
            Console.WriteLine("Geben sie die erste y-Koordinate ein");
            double y1 = double.Parse(Console.ReadLine());
            Console.WriteLine("Geben sie die zweite x-Koordinate ein");
            double x2 = double.Parse(Console.ReadLine());
            Console.WriteLine("Geben sie die zweite y-Koordinate ein");
            double y2 = double.Parse(Console.ReadLine());

            Console.WriteLine("Seite a = " + Seitenlaenge(x1, y1, 0, 0) + " cm");
            Console.WriteLine("Seite b = " + Seitenlaenge(x2, y2, 0, 0) + " cm");
            Console.WriteLine("Seite c = " + Seitenlaenge(x1, y1, x2, y2) + " cm");
            Console.WriteLine("Winkel alpha = " + Winkel(Seitenlaenge(x1, y1, 0 ,0), Seitenlaenge(x2, y2, 0, 0),Seitenlaenge(x1, y1, x2, y2)) + " Grad");
            Console.WriteLine("Winkel alpha = " + Winkel(Seitenlaenge(x2, y2, 0, 0), Seitenlaenge(x1, y1, 0, 0), Seitenlaenge(x1, y1, x2, y2)) + " Grad");
            Console.WriteLine("Winkel alpha = " + Winkel(Seitenlaenge(x1, y1, x2, y2), Seitenlaenge(x2, y2, 0, 0), Seitenlaenge(x1, y1, 0, 0)) + " Grad");
            Console.WriteLine("Die Fläche beträgt " + Flaeche(Seitenlaenge(x1, y1, 0, 0), Seitenlaenge(x2, y2, 0, 0), Seitenlaenge(x1, x2, y1, y2)) + " cm^2");
            Console.ReadLine();
        }
    }
}

Kommentare:

Für diese Lösung gibt es noch keinen Kommentar

Bitte melden Sie sich an um eine Kommentar zu schreiben.
Kommentar schreiben