November 26, 2010

C# 平面折射程式!! 終於...完成了

最近在用C#寫後臺管理程式
寫著寫著突然想到  上學期作專題 
老師出了一個題目寫一套透鏡折射的程式
當時花了一段時間研究寫不出來
今天想到   花了大概3個小時
研究把方程式式換成C#程式
沒想到終於完成了
雖然目前只完成平面折射
但之後要寫透鏡的應該沒問題



-----------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace test
{
    public partial class Form1 : Form
    {
        
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            double n1, n2, distance, ang1, ang2,mat3;
            int x1, y1;
            n1 = 1;
            n2 = 0.8;
            distance = 200;
            ang1 = Math.Atan(1) * 180.0 / Math.PI;
            ang2 = Math.Asin(n1 / n2 * Math.Sin(ang1 * Math.PI / 180)) * 180.0 / Math.PI;
            
            mat3 = 200+distance*Math.Cos(ang2 * Math.PI / 180) ;//檢驗用
            x1 = Convert.ToInt32(200 + distance * Math.Cos(ang2 * Math.PI / 180));
            y1 = Convert.ToInt32(200 + distance * Math.Sin(ang2 * Math.PI / 180));
            label1.Text = Convert.ToString(ang1);//檢驗用
            label2.Text = Convert.ToString(ang2);//檢驗用
            label3.Text = Convert.ToString(x1);//檢驗用
            label4.Text = Convert.ToString(y1);//檢驗用

            Graphics d = this.CreateGraphics();
            Pen b1 = new Pen(Color.Red, 6);
            d.DrawLine(b1, 0, 0, 200, 200); //入射線
            d.DrawLine(b1, 200, 0, 200, 400); //十字線
            d.DrawLine(b1, 0, 200, 400, 200); //十字線
            d.DrawLine(b1, 200, 200, x1, y1); //折射線
        }

      }   
}

0推薦此文章
Today's Visitors: 0 Total Visitors: 48
Personal Category: Uncategorized Articles Topic: feeling / personal / murmur
[Trackback URL]

Reply
  • 1樓

    1樓搶頭香

    滿嘴洋溢著幸福的滋味.就像戀愛般的感覺.

    高雄果豆家夏威夷豆塔

    太妃糖夏威夷豆塔[1盒12個$280元]
    海鹽牛奶夏威夷豆塔[1盒12個$280元]
    桔香檸檬夏威夷豆塔[1盒12個$280元]

    http://kodo.aircamel.com.tw/

    09676b85-d966-4569-a768-f1784380b789

  • '新型態伴手禮 at January 17, 2012 05:52 PM comment | Homepage
Post A Comment









Yes No



Please input the magic number:

( Prevent the annoy garbage messages )
( What if you cannot see the numbers? )
Please input the magic number

誰來收藏
Loading ...
unlog_NVPO 0