using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Security.Policy;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace navigation
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.Size = new Size(450,550);
}
double LatS, LatE, LonS, LonE, l, Lm, Dlo, p, Dist, Co,C, LatVertex,Dlov, Degs, D, M, S;
private void button1_Click(object sender, EventArgs e)
{
//宣告變數
double LatS, LatE, LonS, LonE, Co, Dist, LatVertex,Dlov;
//獲得出發點與目的地的值
LatS = Convert.ToDouble(textBox1.Text) + Convert.ToDouble(textBox2.Text) / 60 + Convert.ToDouble(textBox3.Text) / 3600;
LonS = Convert.ToDouble(textBox4.Text) + Convert.ToDouble(textBox5.Text) / 60 + Convert.ToDouble(textBox6.Text) / 3600;
LatE = Convert.ToDouble(textBox7.Text) + Convert.ToDouble(textBox8.Text) / 60 + Convert.ToDouble(textBox9.Text) / 3600;
LonE = Convert.ToDouble(textBox10.Text) + Convert.ToDouble(textBox11.Text) /60 + Convert.ToDouble(textBox12.Text) /3600;
//用if判斷ComboBox裡面的方位
if (comboBox1.Text == "S")
{
LatS = LatS * -1;
}
if (comboBox2.Text == "W")
{
LonS = LonS * -1;
}
if (comboBox3.Text == "S")
{
LatE = LatE * -1;
}
if (comboBox4.Text == "W")
{
LonE = LonE * -1;
}
Dist = 0;
Co = 0;
LatVertex = 0;
Dlov = 0;
if (comboBox3.Text=="Middle_Latitude")
{
this.Middle_Latitude_CoAndDist(LatS, LonS, LatE, LonE, ref Dist, ref Co);
}
if (comboBox3.Text == "Mercator")
{
this.Mercator_CoAndDist(LatS, LonS, LatE, LonE, ref Dist, ref Co);
}
if (comboBox3.Text == "Great_Circle")
{
this.GreatCirle_CoAndDist(LatS, LonS, LatE, LonE, ref Dist, ref C,ref LatVertex,ref Dlov);
}
textBox13.Text = Co.ToString();
textBox14.Text = Dist.ToString();
if (comboBox3.Text == "Great_Circle")
{
textBox13.Text = C.ToString();
textBox15.Text = LatVertex.ToString();
textBox16.Text = Dlov.ToString();
}
}
private void button2_Click(object sender, EventArgs e)
{
LatS = Convert.ToDouble(textBox1.Text) + Convert.ToDouble(textBox2.Text) / 60 + Convert.ToDouble(textBox3.Text) / 3600;
LonS = Convert.ToDouble(textBox4.Text) + Convert.ToDouble(textBox5.Text) / 60 + Convert.ToDouble(textBox6.Text) / 3600;
if (comboBox3.Text =="Middle_Latitude")
{
this.Middle_Latitude_Destination(LatS,LonS,Dist,Co,ref LatE,ref LonE);
}
if (comboBox3.Text == "Mercator")
{
this.Mercator_Destination(LatS, LonS, Dist, Co, ref LatE, ref LonE);
}
if (comboBox3.Text == "Great_Circle")
{
this.Great_Circle_Destination(LatS, LonS, Dist, Co, ref LatE, ref LonE);
}
if (LonE < 0)
{
comboBox4.Text = "W"; // 經度為負,設置為西經
}
else
{
comboBox4.Text = "E"; // 經度為正,設置為東經
}
if (LatE < 0)
{
comboBox3.Text = "S"; // 緯度為負,設置為南緯
}
else
{
comboBox3.Text = "N"; // 緯度為正,設置為北緯
}
//度轉度分秒,並呈現在textBox
Degs = Math.Abs(LatE);
D = (int)Degs;
M = (int)((Degs - D) * 60);
S = (Degs - D - M / 60) * 3600;
textBox7.Text = D.ToString("000");
textBox8.Text = M.ToString("00");
textBox9.Text = S.ToString();
Degs = LonE;
D = (int)Degs;
M = (int)((Degs - D) * 60);
S = (Degs - D - M / 60) * 3600;
textBox10.Text = D.ToString("000");
textBox11.Text = M.ToString("00");
textBox12.Text = S.ToString("");
}
private void button3_Click(object sender, EventArgs e)
{
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
textBox5.Clear();
textBox6.Clear();
textBox7.Clear();
textBox8.Clear();
textBox9.Clear();
textBox10.Clear();
textBox11.Clear();
textBox12.Clear();
textBox13.Clear();
textBox14.Clear();
textBox15.Clear();
textBox16.Clear();
}
private void button4_Click(object sender, EventArgs e)
{
}
private void button5_Click(object sender, EventArgs e)
{
}
private void button6_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void Middle_Latitude_CoAndDist(double LatS, double LonS, double LatE, double LonE, ref double Dist, ref double Co)
{
//計算
l = LatE - LatS;
Lm = (LatE + LatS) / 2;
Dlo = LonE - LonS;
//修正Dlo
if (Dlo > 180)
{
Dlo = Dlo - 360;
}
else if (Dlo < -180)
{
Dlo = Dlo + 360;
}
p = Dlo * Math.Cos(Lm * Math.PI / 180);
if (Lm == 0)
{
p = Dlo;
}
if (l == 0)
{
if (Dlo > 0) { Co = 90; }
else if (Dlo < 0) { Co = 270; }
Dist = Math.Abs(Dlo * Math.Cos(LatS * Math.PI / 180) * 60);
}
else
{
Co = Math.Atan2(p , l);
Dist = (Math.Abs(l / Math.Cos(Co))) * 60;
Co = Co * 180 / Math.PI;
}
//修正(因為前面有修正+象限問題,這裡航向角是負的)
/*if (l < 0)
{
Co = Co + 180;
}
else if (l > 0 & Dlo < 0)
{
Co = Co + 360;
}
else if (Co > 360)
{
Co = Co - 360;
}
*/
}
private void Mercator_CoAndDist(double LatS, double LonS, double LatE, double LonE, ref double Dist, ref double Co)
{
//計算
l = LatE - LatS;
Dlo = LonE - LonS;
//計算出緯度見長比數差(m)
double M1, M2, m;
M1 = 7915.704468 * Math.Log(Math.Tan(45 + LatS / 2)) - 23.0133633 * Math.Sin(LatS) - 0.051353 * Math.Pow(Math.Sin(LatS), 3) - 0.000206 * Math.Pow(Math.Sin(LatS), 5);
M2 = 7915.704468 * Math.Log(Math.Tan(45 + LatE / 2)) - 23.0133633 * Math.Sin(LatE) - 0.051353 * Math.Pow(Math.Sin(LatE), 3) - 0.000206 * Math.Pow(Math.Sin(LatE), 5);
m = 0;
if (LatS > 0 && LatE < 0)
{
m = M2 + M1;
}
else if (LatS < 0 && LatE > 0)
{
m = M2 + M1;
}
else if (M1 > M2)
{
m = M1 - M2;
}
else if (M1 < M2)
{
m = M2 - M1;
}
Co = Math.Atan(Dlo /m);
if (Dlo > 180)
{
Dlo = Dlo - 360;
}
else if (Dlo < -180)
{
Dlo = Dlo + 360;
}
p = Dlo * Math.Cos(Lm * Math.PI / 180);
//防止變成平行
Lm = (LatE + LatS) / 2;
if (Lm == 0)
{
p = Dlo;
}
//防止變成平行
if (l == 0)
{
if (Dlo > 0) { Co = 90; }
else if (Dlo < 0) { Co = 270; }
Dist = Math.Abs(Dlo * Math.Cos(LatS * Math.PI / 180) * 60);
}
else
{
Co = Math.Atan(p / l);
Dist = (Math.Abs(l / Math.Cos(Co))) * 60;
Co = Co * 180 / Math.PI;
}
//修正(因為前面有修正+象限問題,這裡航向角是負的)
if (l < 0)
{
Co = Co + 180;
}
else if (l > 0 & Dlo < 0)
{
Co = Co + 360;
}
else if (Co > 360)
{
Co = Co - 360;
}
}
private void GreatCirle_CoAndDist(double LatS,double LonS,double LatE,double LonE,ref double Dist,ref double C,ref double LatVertex, ref double Dlov)
{
//求Dist&C(起始點航向)
Dlo = (LonE - LonS) * Math.PI / 180;
if (Dlo > 180)
{
Dlo = Dlo - 360;
}
else if (Dlo < -180)
{
Dlo = Dlo + 360;
}
Dist = Math.Acos(Math.Sin(LatS) * Math.Sin(LatE) + Math.Cos(LatS) * Math.Cos(LatE) * Math.Cos(Dlo));
C = Math.Acos((Math.Sin(LatE) - Math.Sin(LatS) * Math.Cos(Dist))/(Math.Cos(LatS)*Math.Sin(Dist)));
//求LatVertex
LatVertex = Math.Acos(Math.Cos(LatS)*Math.Sin(C));
//求起點到大圈頂點的距離
Dlov = Math.Asin(Math.Cos(C)/Math.Sin(LatVertex));
}
private void Middle_Latitude_Destination(double LatS,double LonS,double Dist,double Co,ref double LatE,ref double LonE)
{
//用if判斷ComboBox裡面的方位
if (comboBox1.Text == "S")
{
LatS = LatS * -1;
}
if (comboBox2.Text == "W")
{
LonS = LonS * -1;
}
Dist = Convert.ToDouble(textBox13.Text) / 60;
Co = Convert.ToDouble(textBox14.Text) * Math.PI / 180;
//計算
l = Dist * Math.Cos(Co);
LatE = (LatS + l);
Lm = (LatS + LatE) / 2 * Math.PI / 180;
p = l * Math.Tan(Co);
Dlo = p / Math.Cos(Lm);
LonE = (LonS + Dlo);
}
private void Mercator_Destination(double LatS, double LonS, double Dist, double Co, ref double LatE, ref double LonE)
{
//用if判斷ComboBox裡面的方位
if (comboBox1.Text == "S")
{
LatS = LatS * -1;
}
if (comboBox2.Text == "W")
{
LonS = LonS * -1;
}
//距離分換度,方位度換
Dist = Convert.ToDouble(textBox13.Text) / 60;
Co = Convert.ToDouble(textBox14.Text) * Math.PI / 180;
//計算l&LatE
l = Dist * Math.Cos(Co);
LatE = (LatS + l);
//計算出緯度見長比數差(m)
double M1, M2, m;
M1 = 7915.704468 * Math.Log(Math.Tan(45 + LatS / 2)) - 23.0133633 * Math.Sin(LatS) - 0.051353 * Math.Pow(Math.Sin(LatS), 3) - 0.000206 * Math.Pow(Math.Sin(LatS), 5);
M2 = 7915.704468 * Math.Log(Math.Tan(45 + LatE / 2)) - 23.0133633 * Math.Sin(LatE) - 0.051353 * Math.Pow(Math.Sin(LatE), 3) - 0.000206 * Math.Pow(Math.Sin(LatE), 5);
m = 0;
if (LatS > 0 && LatE < 0)
{
m = M2 + M1;
}
else if (LatS < 0 && LatE > 0)
{
m = M2 + M1;
}
else if (M1 > M2)
{
m = M1 - M2;
}
else if (M1 < M2)
{
m = M2 - M1;
}
//求Dlo
Dlo = Math.Tan(Co) / m;
LonE = LonS + Dlo;
}
private void Great_Circle_Destination(double LatS, double LonS, double Dist, double Co, ref double LatE, ref double LonE)
{
}
}
}
第34行的LonE為何125+12/60+12/3600後是0?
LonE = Convert.ToDouble(textBox10.Text) + Convert.ToDouble(textBox11.Text) /60 + Convert.ToDouble(textBox12.Text) /3600;
2024/12/03(以解決)
之前用的時候把滑鼠放在變數上會出現數值,可以讓我找是哪裡出了問題,可是不知道動到甚麼設定,現在執行程式(偵錯)設中斷點的時候把滑鼠放在變數上沒出現數字。
拜託幫幫我,我功課做不出來,現在連找錯誤都沒辦法找,我快窒息了,好焦慮:(
圖一是現況
圖二是以前正常的時候
影片後面啟動偵錯以後我滑鼠放在程式碼上看變數的數值,但電腦內建的XBOX錄影沒錄進去,呈現出來的畫面就如同圖一。
你這段程式碼前面有沒有什麼條件式?
看起來偵錯點沒有被觸發到呀
程式碼只有一小段不能確定你實際遇到的狀況
第34行的LonE為何125+12/60+12/3600後是0?
LonE = Convert.ToDouble(textBox10.Text) + Convert.ToDouble(textBox11.Text) /60 + Convert.ToDouble(textBox12.Text) /3600;
既然你現在都可以用偵錯點檢查變數的值了,那也請你用相同的方式來檢查你的每個TextBox所傳入的值。
雖然畫面是仿照老師的樣子,但每個TextBox的名稱可能會不同,我是建議你每個TextBox都用容易辨識的名稱做區分(例如:距離就用txt_distance不要再用textBox幾),否則程式碼會很難看得懂。