Home   Cover Cover Cover Cover
 

Dreiecksberechnung

A02.cs
using System;

class Triangle {
  
  // Reads the base c and its two angles alpha and beta from the
  // command line and computes the sides a and b using the law of sines:
  // a:b:c = sin(alpha):sin(beta):sin(gamma)
  static void Main(string[] arg) {
    double c = Convert.ToDouble(arg[0]);     // base
    double alpha = Convert.ToDouble(arg[1]); // in degrees
    double beta = Convert.ToDouble(arg[2]);  // in degrees
    double gamma = 180 - alpha - beta;
    
    double b = c * Math.Sin(beta * Math.PI / 180) / Math.Sin(gamma * Math.PI / 180);
    double a = c * Math.Sin(alpha * Math.PI / 180) / Math.Sin(gamma * Math.PI / 180);
    
    Console.WriteLine("a = {0:f2}, b = {1:f2}", a, b);
  }
}