博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
测量中角度处理常用函数
阅读量:4582 次
发布时间:2019-06-09

本文共 5236 字,大约阅读时间需要 17 分钟。

 

 

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Windows.Forms;namespace 改为相关项目的命名空间{    ///     /// 常用角度处理类    ///     /// 
llc3s@foxmail.com
public class CommonAngleFun { #region 十进制度转化为弧度 /// /// 十进制度转化为弧度 /// /// ///
public static double deg2rad(double dd) { return dd * Math.PI / 180.0; } #endregion #region 空格分隔的度分秒转化为十进制度 /// /// 空格分隔的度分秒转化为十进制度 /// /// public static double str2dfm(string temp) { temp = temp.Trim(); double[] ang = new double[3]; double j = -1.0; //验证是否为合格的度分秒 try { string[] angles = temp.Split(" ".ToCharArray()); if (angles.Length != 3) { MessageBox.Show("度分秒格式不合格"); return j; } for (int i = 0; i < 3; i++) { ang[i] = double.Parse(angles[i]); } j = ang[0] + ang[1] / 60 + ang[2] / 3600; } catch { MessageBox.Show("不是合格的度分秒数据,度分秒之间以空格分隔"); } return j; } #endregion #region 空格分隔的度分秒字符串转化为弧度 /// /// 空格分隔的度分秒转化为弧度 /// /// ///
public static double str2rad(string temp) { return deg2rad(str2dfm(temp)); } #endregion #region 弧度转化为十进制度 /// /// 弧度转化为十进制度分秒 /// /// public static double rad2Degree(double rad) { double degree = rad * 180 / Math.PI; return degree; } #endregion #region 十进制度转化为度分秒 /// /// 十进制度转化为度分秒 /// /// /// 表示十进制度转化为度分秒时秒位保留的小数位数 ///
public static double[] degree2DFM(double degree,int n) { double[] dfm = new double[3]; double d = Math.Floor(degree); double f = Math.Floor((degree - d) * 60); double m = Math.Round(((degree - d) * 60 - f) * 60,0); dfm[0] = d; dfm[1] = f; dfm[2] = m; return dfm; } #endregion #region 度分秒转化为空格分隔的字符串 /// /// 度分秒转化为空格分隔的字符串 /// /// ///
public static string dfm2Str(double[] dfm) { string str = string.Empty; for (int i = 0; i < dfm.Length; i++) { str += dfm[i].ToString() + " "; } return str; } #endregion #region 弧度转化为空格分隔的度分秒字符串 /// /// 弧度转化为空格分隔的度分秒字符串 /// /// /// 十进制度转化为度分秒时秒位的小数位数 ///
public static string rad2StrDfm(double rad,int n) { return dfm2Str(degree2DFM(rad2Degree(rad),n)); } #endregion #region 夹角计算 /// /// 夹角计算.用于测量中方向观测法或类似的夹角计算 /// /// /// ///
private double[] jiajiao(double[] ang1, double[] ang2) { if (ang1.Length != 3 || ang2.Length != 3) { MessageBox.Show("错误"); return null; } else { //预处理 //度位待求方向是否大于0方向,不大于,加360; if (ang2[0] < ang1[0]) ang2[0] += 360; //bool mj = false; //bool dj = false; //度/分借位标记. if (ang2[2] < ang1[2]) { //mj = true; ang2[2] += 60; ang2[1] -= 1; //秒位加60,分位-1 } if (ang2[1] < ang1[1]) { //dj=true; ang2[1] += 60; ang2[0] -= 1; //分位加60,度位-1; } //开始计算 double[] result = new double[3]; for (int i = 0; i < 3; i++) { result[i] = ang2[i] - ang1[i]; } return result; } } #endregion #region 方位角计算 /// /// 方位角计算(第二个点减第一个点) /// /// 第一个点 /// 第一个点 /// 第二个点 /// 第二个点 ///
public static double fangweijiao(double x1, double y1, double x2, double y2) { double fjrad = Math.Atan(Math.Abs((y1 - y2) / (x1 - x2))); //判断象限 //第一象限 if (y2 - y1 > 0 && x2 - x1 > 0) return fjrad; //第二象限 else if (y2 - y1 > 0 && x2 - x1 < 0) { return Math.PI - fjrad; } else if (y2 - y1 < 0 && x2 - x1 < 0) { //第三象限 return Math.PI + fjrad; } else if (y2 - y1 < 0 && x2 - x1 > 0) { //第四象限 return (Math.PI * 2 - fjrad); } else return -1; } #endregion #region 任意两方位角的夹角计算 #endregion }}

 

转载于:https://www.cnblogs.com/DayDreamEveryWhere/p/3160700.html

你可能感兴趣的文章
C# 修饰符
查看>>
java中使用session的一些细节
查看>>
浏览器输入服务器端口号来访问html网页
查看>>
hdu 6435 CSGO(最大曼哈顿距离)
查看>>
logback框架之——日志分割所带来的潜在问题
查看>>
链路追踪工具之Zipkin学习小记
查看>>
iOS中通讯录的开发
查看>>
怎么让table中的<td>内容向上对齐
查看>>
[Java] 遍历HashMap和HashMap转换成List的两种方式
查看>>
mongodb
查看>>
LeetCode 46. Permutations
查看>>
jmeter- 性能测试3:聚合报告(Aggregate Report )
查看>>
JavaScript高级程序设计---学习笔记(二)
查看>>
vim 插件的学习
查看>>
Uncaught SyntaxError: Unexpected token ILLEGAL
查看>>
一个预处理定义的问题
查看>>
ANDROID L——Material Design综合应用(Demo)
查看>>
自我介绍以及关于软件工程的问题
查看>>
struts (一)
查看>>
【新番推荐】工作细胞
查看>>