附和导线平差程序(by C#)

  • 内容简介
  • 过程简介
  • 程序源码
    • 矩阵类Matrix
    • 点类Point
    • 角类Angle
    • 主程序
  • 更新

内容简介

本文主要内容包括本人编写附和导线平差程序的过程及附和导线平差程序源代码,在此记录,以供有兴趣的朋友参考学习。

过程简介

最近学习《C#(注:读音为C sharp)程序设计》这门课时,老师布置了一个设计导线平差程序的作业,一直在学python,好久没用类C语言了,很是头大,好在参考博主:流浪猪头拯救地球的一系列文章,终于是将程序编写出来。
(2020/12/7:初始版本优点是方便上手,缺点是还有很多地方可以优化,下一版本将在不久后更新,coding……)

程序源码

附和导线平差C#程序工程文件及用于测试的文本已上传至附和导线平差C#程序。
此程序一共用到三个类库,分别是矩阵类Matrix、点类Point、角类Angle。

矩阵类Matrix

此类库代码量过大,无法放入博文中,有兴趣的话可以从C#矩阵类库下载。

点类Point

using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;//与PointF 联系起来了namespace work //这里改成和您的namespace 名字一样即可
{public class Point{//Define fieldspublic string name;public double x;    //coordinatepublic double y;public double z;public string Name{ get { return name; } set { name = value; } }public double X{ get { return x; } set { x = value; } }public double Y{ get { return y; } set { y = value; } }public double Z{ get { return z; } set { z = value; } }//The constructorpublic Point(double x = 0, double y = 0, double z = 0, string name = "0"){//构造函数1,将一串数据传到一个 Point 中this.name = name;this.x = x;this.y = y;this.z = z;}public Point(string[] sArry, int mod = 0){//构造函数2,重载 Point函数,将一个字符串数组传到 Point 中//mod 1带名字,0 不带名字,默认不带名字int n = sArry.Length;if (mod == 1){this.name = sArry[0];this.x = double.Parse(sArry[1]);this.y = double.Parse(sArry[2]);if (n < 4)this.z = 0;elsethis.z = double.Parse(sArry[3]);}else{this.x = double.Parse(sArry[0]);this.y = double.Parse(sArry[1]);if (n < 3)this.z = 0;elsethis.z = double.Parse(sArry[2]);}}public Point(Point p1, double s, Angle a){//构造函数3 已知基点,边长,方位角,求另一个点this.x = p1.x + s * a.cos;this.y = p1.y + s * a.sin;this.z = p1.z;this.name = "0";}public Point(PointF p1){//构造函数4 将 PointF 转化为 Point, 需要using System.Drawing;this.x = p1.X;this.y = p1.Y;this.z = 0;this.name = "0";}public Point Add(Point p2){//两点相加return new Point(this.x + p2.x, this.y + p2.y, this.z + p2.z);}public Point Sub(Point p2){//两点相减return new Point(this.x - p2.x, this.y - p2.y, this.z - p2.z);}public Point Mut(double d){//点与数相乘return new Point(this.x * d, this.y * d, this.z * d);}public Point Div(double d){//点与数相除return new Point(this.x / d, this.y / d, this.z / d);}public double Dis(Point p2){//求距离return Math.Sqrt((this.x - p2.x) * (this.x - p2.x) + (this.y - p2.y) *(this.y - p2.y) + (this.z - p2.z) * (this.z - p2.z));}public Angle getAn(Point p2){//以此点为基点,得到其到另一个点的坐标方位角return new Angle(arctan(this.x - p2.x, this.y - p2.y));}public bool IsClose0(Point p2){//判断 其与p2 哪个和(0,0)更接近if (Math.Abs(this.x) < Math.Abs(p2.x) &&Math.Abs(this.y) < Math.Abs(p2.y) &&Math.Abs(this.x) < Math.Abs(p2.x))return true;elsereturn false;}public static int find_Close0(Point[] p){//找出一个点数组中最接近(0,0)的下标int n = p.Length, index = 0;for (int i = 1; i < n; i++){if (p[i].IsClose0(p[index]))index = i;}return index;}/*此函数用于求象限角* 返回的是弧度,取值范围为[0,2*pi)*/public static double arctan(double dx, double dy){double angle = 0;if (dx == 0){if (dy > 0) angle = Math.PI * 0.5;else angle = Math.PI * 1.5;return angle;}angle = Math.Atan2(Math.Abs(dy), Math.Abs(dx));if (dx < 0){if (dy < 0) angle = Math.PI + angle;else angle = Math.PI - angle;}else if (dy < 0) angle = 2 * Math.PI - angle;return angle;}public void show(){//打印出点坐标Console.WriteLine("X {0:f3},   Y {1:f3},   Z {2:f3},   Name {3}", this.x, this.y, this.z, this.name);}public double Dis2To0(){//到原点距离的平方return this.x * this.x + this.y * this.y + this.z * this.z;}public static Point[] ZXH(Point[] pt){//坐标重心化,最后一个点存重心坐标int n = pt.Length;Point[] po = new Point[n + 1];double x0 = 0, y0 = 0, z0 = 0;for (int i = 0; i < n; i++){x0 += pt[i].x;y0 += pt[i].y;z0 += pt[i].z;}x0 /= n; y0 /= n; z0 /= n;for (int i = 0; i < n; i++){po[i] = new Point();po[i].name = pt[i].name;po[i].x = pt[i].x - x0;po[i].y = pt[i].y - y0;po[i].z = pt[i].z - z0;}po[n] = new Point(x0, y0, z0, "ZX");return po;}//重载一些操作符public static Point operator +(Point m1, Point m2) { return m1.Add(m2); }public static Point operator -(Point m1, Point m2) { return m1.Sub(m2); }public static Point operator *(Point m1, double d) { return m1.Mut(d); }public static Point operator *(double d, Point m1) { return m1.Mut(d); }public static Point operator /(Point m1, double d) { return m1.Div(d); }//public static Point operator =(Point m1) {}}}

角类Angle

using System;
using System.Collections.Generic;
using System.Text;
//using work;namespace work
{public class Angle{//角类public int d;    //coordinatepublic int f;public double m;public double ad;public double rad;public int D{ get { return d; } set { d = value; } }public int F{ get { return f; } set { f = value; } }public double M{ get { return m; } set { m = value; } }public double Rad{ get { return rad; } set { rad = value; } }public double Ad{ get { return ad; } set { ad = value; } }public double sin//正弦{ get { return Math.Sin(this.rad); } }public double cos//余弦{ get { return Math.Cos(this.rad); } }public double tan//正切{ get { return Math.Tan(this.rad); } }public double csc//余割{ get { return 1 / Math.Sin(this.rad); } }public double sec//正割{ get { return 1 / Math.Cos(this.rad); } }public double cot//余切{ get { return 1 / Math.Tan(this.rad); } }//The constructor 构造函数public Angle(int d = 0, int f = 0, double m = 0){//构造函数1,将一串数据传到一个 Angle 中,顺便算出弧度this.d = d;this.f = f;this.m = m;this.rad = (d + f / 60.0 + m / 3600) * Math.PI / 180;this.ad = this.rad * 180 / Math.PI;}public Angle(double rad){//构造函数2,将弧度传到一个 Angle 中,顺便算出度分秒this.rad = rad; rad = rad / Math.PI * 180;//度this.d = (int)rad; rad -= this.d; rad *= 60;//分this.f = (int)rad; rad -= this.f; rad *= 60;//秒this.m = rad;this.ad = this.rad * 180 / Math.PI;}public Angle(string[] sArray){//构造函数3,将字符数组传到一个 Angle 中,顺便算出弧度this.d = int.Parse(sArray[0]);this.f = int.Parse(sArray[1]);this.m = double.Parse(sArray[2]);this.rad = (d + f / 60.0 + m / 3600) * Math.PI / 180;this.ad = this.rad * 180 / Math.PI;}public Angle(Angle other){//拷贝构造函数rad = other.rad;d = other.d;f = other.f;m = other.m;this.ad = this.rad * 180 / Math.PI;}public Angle(string str){//构造函数4,将字符串传到一个 Angle 中,顺便算出弧度string[] sArry = str.Split(new string[] { " ", ",", ".", "°", "'", "\"" }, StringSplitOptions.RemoveEmptyEntries);this.d = int.Parse(sArry[0]);this.f = int.Parse(sArry[1]);this.m = double.Parse(sArry[2]);this.rad = (d + f / 60.0 + m / 3600) * Math.PI / 180;this.ad = this.rad * 180 / Math.PI;}//运算函数public Angle Add(Angle other){Angle result = new Angle(this);result.rad += other.rad;result.rad = result.rad % (Math.PI * 2);return new Angle(result.rad);}public Angle Subtract(Angle other){Angle result = new Angle(this);result.rad -= other.rad;//result.rad = (result.rad + 2 * Math.PI) % (Math.PI * 2);return new Angle(result.rad);}public Angle Multiply(double d){Angle result = new Angle(this);result.rad *= d;result.rad = result.rad % (Math.PI * 2);return new Angle(result.rad);}public Angle Divide(double d){Angle result = new Angle(this);result.rad /= d;result.rad = result.rad % (Math.PI * 2);return new Angle(result.rad);}public string ToString(string sDelim = null){//将角转化为字符串,sDelim是分隔符,默认'°′″'if (sDelim == null)return d.ToString() + "°" + f.ToString() + "'" + Math.Round(m, 1).ToString() + "\"";else return d.ToString() + sDelim + f.ToString() + sDelim + Math.Round(m, 1).ToString();}public void show(){//打印出点坐标Console.WriteLine("D {0:d3},   F {1:d3},   M {2:f3}", this.d, this.f, this.m);}//重载运算符public static Angle operator +(Angle m1, Angle m2) { return m1.Add(m2); }public static Angle operator -(Angle m1, Angle m2) { return m1.Subtract(m2); }public static Angle operator -(Angle m1) { return new Angle(-m1.rad); }public static Angle operator *(double d, Angle m1) { return m1.Multiply(d); }public static Angle operator *(Angle m1, double d) { return m1.Multiply(d); }public static Angle operator /(Angle m1, double d) { return m1.Divide(d); }public static Angle operator %(Angle m1, Angle m2) { return new Angle(m1.rad % m2.rad); }public static bool operator >(Angle m1, Angle m2) { return m1.rad > m2.rad; }public static bool operator <(Angle m1, Angle m2) { return m1.rad < m2.rad; }public static bool operator ==(Angle m1, Angle m2) { return m1.rad == m2.rad; }public static bool operator >=(Angle m1, Angle m2) { return m1.rad >= m2.rad; }public static bool operator <=(Angle m1, Angle m2) { return m1.rad <= m2.rad; }public static bool operator !=(Angle m1, Angle m2) { return m1.rad != m2.rad; }//旋转矩阵public Matrix R2{//返回此角的二维旋转矩阵:数学坐标系顺时针旋转此角度get{Matrix result = new Matrix(2, 2);result[0, 0] = this.cos; result[0, 1] = this.sin;result[1, 0] = -this.sin; result[1, 1] = this.cos;return result;}}public Matrix Rx{//返回此角的旋转矩阵:绕x轴顺时针旋转此角度get{Matrix result = new Matrix(3, 3);result[0, 0] = 1; result[0, 1] = 0; result[0, 2] = 0;result[1, 0] = 0; result[1, 1] = this.cos; result[1, 2] = this.sin;result[2, 0] = 0; result[2, 1] = -this.sin; result[2, 2] = this.cos;return result;}}public Matrix Ry{//返回此角的旋转矩阵:绕y轴顺时针旋转此角度get{Matrix result = new Matrix(3, 3);result[0, 0] = this.cos; result[0, 1] = 0; result[0, 2] = -this.sin;result[1, 0] = 0; result[1, 1] = 1; result[1, 2] = 0;result[2, 0] = this.sin; result[2, 1] = 0; result[2, 2] = this.cos;return result;}}public Matrix Rz{//返回此角的旋转矩阵:绕z轴顺时针旋转此角度get{Matrix result = new Matrix(3, 3);result[0, 0] = this.cos; result[0, 1] = this.sin; result[0, 2] = 0;result[1, 0] = -this.sin; result[1, 1] = this.cos; result[1, 2] = 0;result[2, 0] = 0; result[2, 1] = 0; result[2, 2] = 1;return result;}}}
}

主程序

using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using System.Linq;
using System.Data.OleDb;using work;
//测站类
public class GPoint
{//Define fieldspublic Point pt;public double s;//观测角(弧度表示),边长public Angle an;//观测角public Point Pt{ get { return pt; } set { pt = value; } }public Angle An{ get { return an; } set { an = value; } }public double S{ get { return s; } set { s = value; } }//The constructorpublic GPoint(double h = 0, double s = 0, string name = "0", double x = 0, double y = 0, double z = 0){//构造函数1this.pt = new Point(x, y, z, name);this.an = new Angle(h);this.s = s;}public GPoint(Point pt, Angle an, double s){//构造函数2this.pt = pt;this.an = an;this.s = s;}//public GPoint(string[] sArry)//{//构造函数3,将字符数组传到一个 GPoint 中,顺便算出弧度//    this.an.d = int.Parse(sArry[0]);//    this.an.f = int.Parse(sArry[1]);//    this.an.m = double.Parse(sArry[2]);//    this.an.rad = (an.d + an.f / 60.0 + an.m / 3600) * Math.PI / 180;//    this.an.ad = this.an.rad * 180 / Math.PI;//}
}public class Read
{/*用sDelim 将str 分割成字符串数组* @sDelim 可选参数,分隔符*/public static string[] Split(string str, string sDelim = null){if (sDelim == null)//默认分割return str.Split(new string[] { " ", ",", "?", "->", "   ", "\t" }, StringSplitOptions.RemoveEmptyEntries);else//根据传入参数分割return str.Split(new string[] { sDelim }, StringSplitOptions.RemoveEmptyEntries);}/*得到一个文本文件的行数*/public static int getTextRows(string txt){int n = 0;StreamReader sR = new StreamReader(txt);string str = sR.ReadLine();while (str != null){if (Split(str) != null) n++;str = sR.ReadLine();}sR.Close();return n;}/*读取txt至点数组中*/public static Point[] T2Po(string txt){int i = 0, n = getTextRows(txt);Point[] Pt = new Point[n];StreamReader sR = new StreamReader(txt);string str = sR.ReadLine();while (str != null){string[] sArray = Split(str);if (sArray != null){Point pt = new Point(sArray, 1);Pt[i] = pt; i++;}str = sR.ReadLine();}sR.Close();return Pt;}public static Angle[] T2An(string txt){int i = 0, n = getTextRows(txt);Angle[] Pt = new Angle[n];StreamReader sR = new StreamReader(txt);string str = sR.ReadLine();while (str != null){string[] sArray = Split(str);if (sArray != null){Angle pt = new Angle(sArray);Pt[i] = pt; i++;}str = sR.ReadLine();}sR.Close();return Pt;}public static double[] T2S(string txt){int i = 0, n = getTextRows(txt);double[] Pt = new double[n];StreamReader sR = new StreamReader(txt);string str = sR.ReadLine();while (str != null){string[] sArray = Split(str);if (sArray != null){double pt = double.Parse(sArray[0]);Pt[i] = pt; i++;}str = sR.ReadLine();}sR.Close();return Pt;}//public static GPoint[] T2GP(string txt)//{//    int i = 0, n = getTextRows(txt);//    GPoint[] Pt = new GPoint[n];//    StreamReader sR = new StreamReader(txt);//    string str = sR.ReadLine();//    while (str != null)//    {//        string[] sArray = Split(str);//        if (sArray != null)//        {//            GPoint pt = new GPoint(sArray);//            Pt[i] = pt; i++;//        }//        str = sR.ReadLine();//    }//    sR.Close();//    return Pt;//}
}
public class DXPC //导线平差
{public static GPoint[] FHDX(GPoint[] data,Angle an1,Angle an2)//附和导线平差,an1、an2分别为始边、终边方位角{//Angle d360 = new Angle(360, 0, 0);Angle d180 = new Angle(180, 0, 0);Angle a = an1;Angle b;Angle fb;//角度闭合差int n = data.Length;Angle[] c= new Angle[n];double[] dx = new double[n];//增量double[] dy = new double[n];double[] ddx = new double[n];//改正量double[] ddy = new double[n];double fx, fy, ex, ey;double sums = 0;//导线全长double fs;//全长闭合差for (int i = 0;i < n;i++)//计算角度闭合差{a = data[i].an + a;if(a>d180){a = a - d180;}else{a = a + d180;}}       b = (an2 - a) / n;fb = (an2 - a);//fb.show();a = an1;for (int i = 0; i < n; i++)//进行角度改正{data[i].an = data[i].an + b;a = data[i].an + a;if (a > d180){a = a - d180;}else{a = a + d180;}c[i] = a;//a.show();}fx = data[0].pt.x;fy = data[0].pt.y;ex = data[n - 1].pt.x;ey = data[n - 1].pt.y;for (int i = 0; i < n-1; i++)//计算坐标增量及x、y方向的导线闭合差及导线全长{dx[i] = data[i].s * c[i].cos;dy[i] = data[i].s * c[i].sin;fx = fx + dx[i];fy = fy + dy[i];sums = sums + data[i].s;}fs = Math.Sqrt((ex - fx) * (ex - fx) + (ey - fy) * (ey - fy));//全长闭合差for (int i = 0; i < n - 1; i++)//计算改正量并对增量改正{ddx[i] = (ex - fx) * data[i].s / sums;ddy[i] = (ey - fy) * data[i].s / sums;dx[i] = dx[i] + ddx[i];dy[i] = dy[i] + ddy[i];}for (int i = 0; i < n - 1; i++)//计算最终坐标{data[i + 1].pt.x = data[i].pt.x + dx[i];data[i + 1].pt.y = data[i].pt.y + dy[i];}if ((1.0 / (sums / fs) < 1.0 / 4000) && (Math.Abs(fb.rad) < new Angle(0, 0, 40 * Math.Sqrt(n)).rad))//检测是否符合限差{Console.WriteLine("符合限差");}else{Console.WriteLine("不符合限差");Console.WriteLine("fs:{0};sums:{1};fb:{2}", fs, sums, fb.m);}return data;}
}namespace Test2017
{class Program{static void Main(string[] args){string fo1 = @"C:\Users\Dr.z\Desktop\HTML\point.txt";string fo2 = @"C:\Users\Dr.z\Desktop\HTML\angle.txt";string fo3 = @"C:\Users\Dr.z\Desktop\HTML\s.txt";Point[] po = Read.T2Po(fo1);//这里我是把T2Po放到一个Read类里面了。Angle[] an = Read.T2An(fo2);double[] s = Read.T2S(fo3);int n = po.Length;GPoint[] gpo = new GPoint[n];for (int i = 0; i < n; i++){gpo[i] = new GPoint(po[i],an[i],s[i]);}gpo = DXPC.FHDX(gpo, new Angle(298, 59, 12), new Angle(182, 10, 45));for(int i = 0;i<n;i++){gpo[i].pt.show();}Console.Read();}}
}

更新

很久之前的东西了,现在已经不太记得了,但发现在CSDN下载是真的不便,就还是改到网盘上会好点。
网盘链接
提取码:c6w8

在此祝各位学有所成,身体健康。(20220317)

附和导线平差程序(by C#)相关推荐

  1. 导线网平差程序系统设计—CSU测绘实习

    目录 一.需求分析 (一)程序总体描述 (二)程序功能需求 二.原理与系统设计 (一)文件结构设计 (二)控制网概算 (三)成果输出 1.成果报表制作 2.网图形的绘制 (四)总体计算流程 三.测试结 ...

  2. 水准路线平差c语言程序,水准网平差程序的设计与实现

    水准网平差程序的设计与实现 维普资讯 http://doc.docsou.com 第1 6卷第 4期 2 0托 l 00 2月 昆明冶金高等专科学校学报 /, v1N 8 I 0. I l 6 . 4 ...

  3. 三角网导线平差实例_导线测量平差实例

    闭合导线: 名称 表示 原理 (导线长) D 实测边长总合 (角度总和) ∑β 实测左角相加的总和 (角度闭合差) Fβ 实测左角相加的总和的秒位数 (坐标闭和差) Fx △ x 计算出的坐标增量之合 ...

  4. 简述导线平差计算的五个步骤_RTK技术导线测量和全站仪导线测量有什么区别?...

    导线测量是测量导线的长度.转角和高程以及推算出坐标等的作业.在导线测量过程中,我们可以选择RTK技术或全站仪进行操作,接下来小编就结合GPS-RTK和全站仪的特点和操作方法来讲解两者的优势. 一.全站 ...

  5. (C#)一个简易的水准网平差程序

    这是用C#链表写的一个简易的水准网按测距平差的窗体程序. 这是运行的窗体界面: 读取的数据格式为:点号,高差,测距.例如: 得出的运行结果如下: 下面就是我的具体代码: using System; u ...

  6. 水准网平差程序Matlab实现 全部代码,详细教程

    一.程序结构: 输入文件格式如下所示: 1 读取文件:主要用到fopen, str2num函数 fid = fopen('input_leveling.txt','r'); line1 = fgetl ...

  7. 三角网导线平差实例_第讲(三角网条件平差.ppt

    第讲(三角网条件平差.ppt 第三章 条件平差 第三章 条件平差 3.2 条件方程 * * * * 内容安排 一.高程控制网条件方程的列立 二.导线网条件方程的列立 三.测角网条件方程的列立 四.测边 ...

  8. 三角网导线平差实例_网平差三角网三边导线网.doc

    网平差三角网三边导线网 五.三角网平差 图-1表示在高级点A.B下加密新点P1,P2的三角网,网中观测了12个方向值L1L2,...,L12.试平差此三角网,求:(1)待定点P1及P2的坐标平差值及其 ...

  9. 三角网导线平差实例_三角网近似平差及边长计算表

    ° ′ ″ ° ° ° ° 1 2 4 5 6 7 8 9 G06 a 1 10 4 59 10.083044444 -0.000205278 10.082839167 ########### 5.6 ...

  10. 利用C#编写一个高斯正反算程序

    一.代码界面展示 整个界面控件为tabControl,groupBox,label,textbox,comboBox,button,richTextBook. 二.代码运算结果展示 数据结果采用国家统 ...

最新文章

  1. 某百度程序员中午面试一个阿里程序员,晚上去阿里面试,面试官竟是中午那个人!
  2. php打印模板插件,smarty的插件功能是smarty模板的精华
  3. 使用scrum开发软件的一般过程是什么?_黑色灌封胶的使用工艺复杂吗?使用过程中应该注意什么?...
  4. HTTP协议详解(转载)
  5. 用jquery动态添加form表单
  6. sklearn—特征工程
  7. mongodb删除文档
  8. 2018年最新Spring Boot视频教程附代码笔记资料(50G)
  9. 【echarts】 tooltip显示图片
  10. 数据结构与算法的实现 —— 结点定义与数据结构的选择
  11. linux 从github拉取更新_2020年的GitHub年度报告,我看出了这些不一样的点
  12. matplotlib易混概念理解与画图详解
  13. 电脑计算机人员英语,计算机专业英语词汇新大全(完美打印版).pdf
  14. Kettle5.4调用Redis
  15. NPOI导出真正的电子表格,支持 自定义多行表头(表头风格设置),支持多个sheet页面导出
  16. 工厂模式之简单工厂、工厂方法与抽象工厂
  17. 7、线性方程组详细解法
  18. 资源管理器 右键 反应慢 现象解决方案
  19. ORACLE学习笔记-CentOS 7.2 Oracle 12C R2安装部署
  20. Citrix PVS7.6 测试调试

热门文章

  1. Oracle查询结果随机排序(去重,抽检)
  2. 最新2020版IDEA下载安装教程
  3. 使用saminside破解WindowsXP密码
  4. AD快捷键设置(自定义)
  5. java创建动态数组_动态数组java实现
  6. [转]富人的28个理财习惯
  7. Android学习(二):Android Studio创建并运行Android项目(Hello World ~.~)
  8. 匿名mahony互补滤波代码详解
  9. 关于集合set()补充
  10. 自己设计过App的数据库框架?还是只是停留在使用ormlite greenDao这类框架,一篇文章帮你解答...