2016-05-28 12 views
0

私はC#の私の最初のプログラムに取り組んでおり、距離と角度の計算に問題があります。私の目的は、X1、Y1値、X2、Y2値を求めて、2点間の距離と角度を計算することです。私は私の(非常に恐ろしい)コードを下に貼り付けます。助けをあらかじめありがとう!Cの距離と角度のコーディング#

 //prompt and store the x and y for two points 
     Console.WriteLine("Please enter X1:"); 
     float point1X = float.Parse(Console.ReadLine()); 
     Console.WriteLine("Please enter Y1:"); 
     float point1Y = float.Parse(Console.ReadLine()); 
     Console.WriteLine("Please enter X2:"); 
     float point2X = float.Parse(Console.ReadLine()); 
     Console.WriteLine("Please enter Y2:"); 
     float point2Y = float.Parse(Console.ReadLine()); 
     Console.WriteLine(""); 

     //calculate the distance 
     double deltaX= Math.Pow(point2X - point1X, 2); 
     double deltaY= Math.Pow(point2Y - point1Y, 2); 
     Console.WriteLine("double deltaX, double deltaY"); 
     Console.WriteLine(""); 

     //calculate the angle 
     double angle = Math.Atan2(deltaX, deltaY); 
     Console.WriteLine("double angle"); 
     Console.WriteLine(""); 
+0

そこで質問はありますか? –

+0

距離と角度の計算を実行する代わりに、 'console.writeline'のみが出力されます。格納された入力に基づいて距離と角度を計算するにはどうすればよいですか? –

答えて

0

これは、あなたが検索このようなものであれば、これは数学ではなく、C#の;-)です:

 //calculate the distance 
     ... 
     Console.WriteLine("Distance : " + Math.Sqrt(deltaX + deltaY)); 

     //calculate the angle 
     double angle = Math.Atan2(point2Y - point1Y, point2X - point1X); 
     ... 
     Console.WriteLine(angle + " Rad"); 
     Console.WriteLine(angle * 180/Math.PI + " Deg"); 
+0

ありがとうございます。あなたが見ることができるように、私はどのようにコードを学習するか(このウェブサイトを使用する方法を学ぶ、タギングなど)の最初の段階にあります。 –

関連する問題