單像空間后方交會程序報告_第1頁
單像空間后方交會程序報告_第2頁
單像空間后方交會程序報告_第3頁
單像空間后方交會程序報告_第4頁
單像空間后方交會程序報告_第5頁
已閱讀5頁,還剩11頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、單像空間后方交會程序報告指導(dǎo)老師:劉老師班 級:測繪 101姓 名:尚鋒學(xué) 號: 19 號1、應(yīng)用程序的主入口部分的代碼:using System;using System.Collections.Generic;using System.Linq;using System.Windows.Forms;namespace 單像空間后方交會static class Program/ / 應(yīng)用程序的主入口點。/ STAThreadstatic void Main()Application .EnableVisualStyles();Application .SetCompatibleTextRen

2、deringDefault( false );Application .Run( new Form1();2、方法解算類(通用)部分的代碼:using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace 單像空間后方交會class Tongyongstruct image_point / 一個像點結(jié)構(gòu),包含像點坐標(biāo)和地面點坐標(biāo) public double x;public double y;public double X;public double Y;privatedoub

3、le f;/ 主距privatedouble u;/u 為外方位元素,下面 5個相同privatedouble w;privatedouble k;privatedouble Xs;privatedouble Ys;privatedouble Zs;privateimage_point p =new image_point 4;/ 四個控制點privatedouble R= new double 9; / 旋轉(zhuǎn)矩陣privatedouble a =new double 8;/ 像點坐標(biāo)近似值privatedouble , A= newdouble 8, 6;/ 誤差方程式系數(shù)privatedo

4、uble L =new double 8; / 誤差方程式常數(shù)項privateint count =0; /統(tǒng)計代次數(shù)publicmTongyong( double g,double q) / 構(gòu)造函數(shù),初始化各變= g;for( int i = 0; i 4; i+)int j = i * 5;pi.x =qj;pi.y =qj + 1;pi.X =qj + 2;pi.Y =qj + 3;pi.Z =qj + 4;double ave = 0, sum = 0;/ 求比例尺分母for( int i = 0; i 3; i+)public double Z;for ( int j = i +

5、1; j 4; j+)量, 單位sum +=Math.Sqrt( Math.Pow(pi.X - pj.X, 2) +Math.Sqrt( Math.Pow(pi.x - pj.x, 2)Math.Pow(pi.Y - pj.Y, 2) / + Math.Pow(pi.y - pj.y, 2); ave = sum / 6; u = 0;/ 給定外方位元素的初始值 , 角度均設(shè)置為 0w = 0;k = 0;/Xs 為四個控Xs = (p0.X + p1.X + p2.X + p3.X) / 4; 制點X的平均值,Ys類似Ys = (p0.Y + p1.Y + p2.Y + p3.Y) / 4

6、;Zs = (p0.Z + p1.Z + p2.Z + p3.Z) / 4 + ave * f;private double sin( double m) / 正弦,為簡化而寫 , 下同return Math.Sin(m); private double cos( double m)return Math.Cos(m); private void calcos() / 計算旋轉(zhuǎn)矩陣R0 = cos(u) * cos(k) - sin(u) * sin(w) * sin(k);R1 = -cos(u) * sin(k) - sin(u) * sin(w) * cos(k);R2 = -sin(u

7、) * cos(w);R3 = cos(w) * sin(k);R4 = cos(w) * cos(k);R5 = -sin(w);R6 = sin(u) * cos(k) + cos(u) * sin(w) * sin(k);R7 = cos(u) * sin(w) * cos(k) - sin(u) * sin(k);R8 = cos(u) * cos(w);private void calabout() / 像點坐標(biāo)的近似值int i;for (i = 0; i 4; i+) a2 * i = -f * (R0 * (pi.X - Xs) + R3 * (pi.Y- Ys) + R6 *

8、 (pi.Z - Zs) / (R2 * (pi.X - Xs) + R5 * (pi.Y- Ys) + R8 * (pi.Z - Zs);a2 * i + 1 = -f * (R1 * (pi.X - Xs) + R4 * (pi.Y - Ys) + R7 * (pi.Z - Zs) / (R2 * (pi.X - Xs) + R5 * (pi.Y- Ys) + R8 * (pi.Z - Zs);private void calxx() / 誤差方程式的系數(shù)和常數(shù)項int i;for (i = 0; i 4; i+)/ 系數(shù)double z = R2 * (pi.X - Xs) + R5 *

9、 (pi.Y - Ys)+ R8 * (pi.Z - Zs); int n = i * 2;An, 0 = (R0 * f + R2 * pi.x) / z;An, 1 = (R3 * f + R5 * pi.x) / z;An, 2 = (R6 * f + R8 * pi.x) / z;An, 3 = pi.y * sin(w) - f * cos(w) * cos(k) - pi.x / f * (pi.x * cos(w) * cos(k) - pi.y * cos(w) * sin(k);An, 4 = -f * sin(k) - pi.x / f * (pi.x * sin(k) +

10、 pi.y * cos(k);An, 5 = pi.y;An + 1, 0 = (R1 * f + R2 * pi.y) / z;An + 1, 1 = (R4 * f + R5 * pi.y) / z;An + 1, 2 = (R7 * f + R8 * pi.y) / z;An + 1, 3 = -pi.x * sin(w) + f * cos(w) * sin(k) -pi.x / f * (pi.x * cos(w) * cos(k) - pi.y * sin(k) * cos(w);An + 1, 4 = -f * cos(k) - pi.y / f * (pi.x * sin(k)

11、 + pi.y * cos(k);An + 1, 5 = -pi.x;for (i = 0; i 4; i+) / 常數(shù)項L2 * i = pi.x - a2 * i;L2 * i + 1 = pi.y - a2 * i + 1;private double calAdd()double , temp =new double 6, 6;A 的轉(zhuǎn)置與 A相乘的積double , ANew =new double 6, 8;/A 的轉(zhuǎn)置double t =new double 6;/A 的轉(zhuǎn)置與 L相乘的積double X =new double6;/ 改正數(shù)int i, j, n;for (i

12、= 0; i 8; i+)/ 求A的轉(zhuǎn)置 ANewfor (j = 0; j 6; j+)ANewj, i = Ai, j;for (i = 0; i 6; i+)/求A的轉(zhuǎn)置與A相乘的積tempfor (j = 0; j 6; j+)tempi, j = 0;for (n = 0; n 8; n+)tempi, j += ANewi, n * An, j;MATINV(temp); /temp 的逆,保存在本身矩陣中 for (i = 0; i 6; i+)/求A的轉(zhuǎn)置與L的乘積tti = 0; for (j = 0; j 8; j+) ti += ANewi, j * Lj;for (i

13、= 0; i 6; i+)/ 求改正數(shù) XXi = 0;for (j = 0; j 0.00001)/ 迭代至最大改正數(shù) =0.00001為止calcos(); calabout();calxx();VALUE = calAdd();count+;private void MATINV(double , c)/ 求6階矩陣的逆int i, j, h, m;const int n = 6; double l;double , q = new double n, 12;for (i = 0; i n; i+) / 構(gòu)造高斯矩陣for (j = 0; j n; j+) qi, j = ci, j;f

14、or (i = 0; i n; i+) / 單位矩陣for (j = n; j 12; j+)if (i + 6 = j)qi, j = 1; else qi, j = 0;for (h = 0, m = 0; m n - 1; m+, h+)/ 消去對角線以下的數(shù)據(jù)for (i = m + 1; i n; i+)if (qi, h = 0d) continue ;l = qm, h / qi, h;for (j = 0; j 0; m-, h-)/ 消去對角線以上的數(shù)據(jù)for (i = m - 1; i = 0; i-)if (qi, h = 0d) continue ;l = qm, h

15、/ qi, h;for (j = 0; j 12; j+)qi, j *= l;qi, j -= qm, j;for (i = 0; i n; i+)/ 將對角線上數(shù)據(jù)化為 1l = 1.0 / qi, i;for (j = 0; j 12; j+)qi, j *= l;for (i = 0; i n; i+)/ 提取逆矩陣for (j = 0; j n; j+)ci, j = qi, j + 6;private double maxone(double Arr)/ 返回六個元素中的最大值double ARR = new double 6;for ( int i = 0; i 6; i+)AR

16、Ri = Arri;if (ARRi 0d) / 取正ARRi = -ARRi;Array .Sort(ARR, 0, 6);return ARR5;public int COUNTgetreturn count;public double Ugetu;returnpublicdoubleWgetreturnw;publicdoubleKgetreturnk;publicdoubleXSgetreturnXs;publicdoubleYSgetreturnYs;publicdoubleZSgetreturnZs;3、窗體一部分的代碼:using System;using System.Coll

17、ections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.Diagnostics;using System.Data.OleDb;using System.IO;namespace 單像空間后方交會public partial class Form1: Formprivate double data = new double 20; /

18、保存表中的數(shù)據(jù) private double f = 0; / 主距 public Form1()InitializeComponent();private void Form1_Load( object sender, EventArgs e)/ TODO: 這行代碼將數(shù)據(jù)加載到表“ database1DataSet1.data 中。您可以根據(jù)需要移動或移除它。this .dataTableAdapter.Fill( this .database1DataSet1.data); copyFile(); / 復(fù)制數(shù)據(jù)文件tryf = 153.24 / 1000;/ 主距為固定值for ( in

19、t i = 0; i 4; i+)int j = 5 * i;dataj =double .Parse( this .DGV.Rowsi.Cells1.Value.ToString() / 1000; dataj + 1 =double .Parse( this .DGV.Rowsi.Cells2.Value.ToString() / 1000; dataj + 2 =double .Parse( this .DGV.Rowsi.Cells3.Value.ToString();dataj + 3 =double .Parse( this .DGV.Rowsi.Cells4.Value.ToSt

20、ring();dataj + 4 =double .Parse( this .DGV.Rowsi.Cells5.Value.ToString(); catch ( Exception o) / 載入數(shù)據(jù)出錯,程序?qū)o法開始計算 MessageBox.Show(o.Message, 提示 ,MessageBoxButtons.OK, MessageBoxIcon.Information);btnStart.Enabled = false ; this .label2.Text = ;this .textBox1.Text = C:Documents and桌面 RESULT.txt ; / 默認(rèn)

21、結(jié)果保存在桌面this .label2.Text = 準(zhǔn)備就緒 ; btnCheck.Enabled = false ; / 查看解算結(jié)果不可用 private void btnExit_Click( object sender, EventArgs e)Application .Exit();private void btnFilePath_Click( object sender, EventArgs e) folderBrowserDialog1.ShowNewFolderButton = true ;if (folderBrowserDialog1.ShowDialog() = Dia

22、logResult .OK) string s = folderBrowserDialog1.SelectedPath + + RESULT.txt ;if (s.Contains( ) = true ) / 解決根目錄下出現(xiàn)如同 C:RESULT.txt 等不正確路徑情況 s = s.Replace( , ); this .textBox1.Text = s;private void btnStart_Click( object sender, EventArgs e) btnCheck.Enabled = false ; / 解算過程中不響應(yīng)按鍵btnExit.Enabled = fals

23、e ;false ;程序解算中,請稍等btnStart.Enabled =this .label2.Text = tryTongyong s = new Tongyong(f, data); / 新建實例解算 ,傳入數(shù)據(jù)s.makeSure(); / 迭代解算this .label2.Text = 解算完成 , 迭代次數(shù) : + s.COUNT.ToString(); / 顯示狀態(tài)StreamWriter/ 保存結(jié)果文件sw = newStreamWriter (this .textBox1.Text);sw.WriteLine(stringsw.WriteLine(stringsw.Writ

24、eLine(stringsw.WriteLine(stringsw.WriteLine(stringsw.WriteLine(stringsw.Close();.Format( u=0:F9 , s.U);.Format( w=0:F10 , s.W);.Format( k=0:F9 , s.K);.Format( Xs=0:F5 , s.XS);.Format( Ys=0:F5 , s.YS);try / 若成功則解算完成后自動打開結(jié)果文檔Process p = new Process ();p.StartInfo.FileName =this .textBox1.Text;.Format( Zs=0:F6 , s.ZS);p.Start(); catch ( Exception o)MessageBox.Show(o.Message, 提示,MessageBoxButtons.OK, MessageBoxIcon.Information);catch / 解算失敗,報錯MessageBox.Show( 解算失敗 ! , 提示 btnCheck.Enabled = btnExit.Enabled = btnStart.Enabled =MessageBoxButtons

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論