円の出力
問題
円の座標x,yをカンマ区切りでファイルに出力しましょう。
可能であれば、出力したxy座標をエクセル等で読み込み、
グラフ機能を使って円を描画しましょう。
出力
・データを出力するファイルはCircle.txt
・単位円のx, y座標を0度から360度まで1度刻みで出力する
・出力形式はカンマ区切りでx座標,y座標(例を参照)
描画
・エクセル等のソフトで読み込む
・散布図グラフ表示機能を使って円を描く
例
Circle.txt
1,0 0.999847695156391,0.0174524064372835 0.999390827019096,0.034899496702501 0.998629534754574,0.0523359562429438 0.997564050259824,0.0697564737441253 0.996194698091746,0.0871557427476582 0.994521895368273,0.104528463267653 (中略) 0.996194698091746,-0.0871557427476583 0.997564050259824,-0.0697564737441256 0.998629534754574,-0.0523359562429444 0.999390827019096,-0.0348994967025008 0.999847695156391,-0.0174524064372836 1,-2.44921270764475E-16
描画
解答例
using System; using System.IO; namespace CreateCircle { class Program { static void Main(string[] args) { String path = @"D:\Documents\enzan1\CreateCircle\Circle.txt"; if(File.Exists(path) == true) { File.Delete(path); } using (StreamWriter sw = File.AppendText(path)) { double rad = Math.PI / 180; for (int i = 0; i <= 360; i++) { double x = Math.Cos(rad*i); double y = Math.Sin(rad*i); sw.WriteLine("{0},{1}", x, y); } } } } }