(20181109)角度转弧度——dms2rad/rad2dms

9 篇文章 0 订阅

因为需要,补充C/C++版本的角度转弧度【参考  测绘程序设计】:

//#include "stdafx.h"
#include <iostream>
using namespace std;

//
//  将度分秒连写的(double型)角度化为弧度值
double dms2rad(double a)
{
	//提取角度值的符号
	double sign = (a<0.0) ? -1.0 : 1.0;
	a = fabs(a);

	//提取角度值的整度
	int d = (int)((a + 0.00001) / 10000.0);
	a = a - d*10000.0;
	if (a<0.0){ d = d - 1; a = a + 10000; }

	//提取角度值的整分及秒值
	int m = (int)((a + 0.00001) / 100.0);
	a = a - m * 100;
	if (a<0.0){ m = m - 1; a = a + 100.0; }

	a = sign*(d*3600.0 + m*60.0 + a) / 206264.806247096363;

	return a;
}


//
//  将角度的弧度值化为度分秒连写的角度(double 型) 
double rad2dms(double a)
{
	a = a*206264.806247096363;

	double sign = (a<0.0) ? -1.0 : 1.0;
	a = fabs(a);

	int d = (int)(a / 3600.0 + 0.0000001);
	a = a - d*3600.0;

	if (a<0.0){ d = d - 1; a = a + 3600.0; }

	int m = (int)(a / 60.0 + 0.0001);
	a = a - m*60.0;
	if (a<0.0){ m = m - 1; a = a + 60.0; }

	a = d*10000.0 + m*100.0 + a;

	return a*sign;
}

int main()
{
	double A = 330545.35;   //33°5'45.35''
	double B = 455145.25;   //45°51'45.25''
	printf("\n A=%lf", A);
	printf("\n B=%lf", B);

	double AB = dms2rad(A) + dms2rad(B);
	printf("\n A+B=%lf", rad2dms(AB));

	printf("\n");


	system("pause");
	return 0;
}

 

 

=========================================

角度转弧度matlab:

function hd=dms2rad(JD);%角度化弧度函数
%JD=99.3527;
  w=abs(JD);
  d=fix(w);
  df=(w-d)*100;
  f=fix(df);
  m=(df-f)*100;
  ddd=d+f/60+m/3600;
  hd=ddd*pi/180;
  if JD<0;
      hd=-hd;
  end
  return

弧度转角度:

function JD=rad2dms(hd)
%弧度化角度函数
   w=abs(hd);
   df=w*180/pi;
   d=fix(df);
   mf=(df-d)*60;
   m=fix(mf);
   sf=(mf-m)*60;
   JD=d+m/100+sf/10000;
   if hd<0;
       JD=-JD;
   end
return

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
A collection of geodetic functions that solve a variety of problems in geodesy. Supports a wide range of common and user-defined reference ellipsoids. Most functions are vectorized. Most recent version can be found at . Functions include: Angle Conversions deg2rad - Degrees to radians dms2deg - Degrees,minutes,seconds to degrees dms2rad - Degrees,minutes,seconds to radians rad2deg - Radians to degrees rad2dms - Radians to degrees,minutes,seconds rad2sec - Radians to seconds sec2rad - Seconds to radians Coordinate Conversions ell2utm - Ellipsoidal (lat,long) to UTM (N,E) coordinates ell2xyz - Ellipsoidal (lat,long) to Cartesian (x,y,z) coodinates sph2xyz - Shperical (az,va,dist) to Cartesian (x,y,z) coordinates xyz2sph - Cartesian (x,y,z) to spherical (az,va,dist) coordinates xyz2ell - Cartesian (x,y,z) to ellipsoidal (lat,long,ht) coordinates xyz2ell2 - xyz2ell with Bowring height formula xyz2ell3 - xyz2ell using complete Bowring version utm2ell - UTM (N,E) to ellipsoidal (lat,long) coordinates Coordinate Transformations refell - Reference ellipsoid definition ellradii - Various radii of curvature ct2lg - Conventional terrestrial (ECEF) to local geodetic (NEU) dg2lg - Differences in Geodetic (lat,lon) to local geodetic (NEU) cct2clg - Conventional terrestrial to local geodetic cov. matrix clg2cct - Local geodetic to conventional terrestrial cov. matrix rotct2lg - Rotation matrix for conventional terrestrial to local geod. rotlg2ct - Rotation matrix for local geod. to conventional terrestrial lg2ct - Local geodetic (NEU) to conventional terrestrial (ECEF) lg2dg - Local geodetic (NEU) to differences in geodetic (lat,lon) direct - Direct geodetic problem (X1,Y1,Z1 + Az,VA,Dist to X2,Y2,Z2) inverse - Inverse geodetic problem (X1,Y1,Z1 + X2,Y2,Z2 to Az,VA,Dist) simil - Similarity transformation (translation,rotation,scale change) Date Conversions cal2jd - Calendar date to Julian date date

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值