Direction between 2 Latitude/Longitude points in C#(C#中2个纬度/经度点之间的方向)
问题描述
我有 2 个经纬度格式的坐标.
I have 2 coordinates in Lat Long format.
我如何确定从 A 点(例如 New York 37.149472,-95.509544 )到 B 点的方向(例如 Toronto 40.714269,-74.005973)
How do I determine from Point A (eg New York 37.149472,-95.509544 ) the direction in degrees to point B (eg Toronto 40.714269,-74.005973)
我正在寻找像340 度"这样的值
I'm looking for a value like "340 Degrees"
在 C# 中
推荐答案
如果你想要一个恒定的方位跟随你不想要最短(大圆)路径,你想要一个 Rhumb 线
If you want a constant bearing to follow you don't want the shortest (great circle) path you want a Rhumb line
Movable Type 脚本的转换
Conversion of the Movable Type Scripts for that
static double DegreeBearing(
double lat1, double lon1,
double lat2, double lon2)
{
var dLon = ToRad(lon2-lon1);
var dPhi = Math.Log(
Math.Tan(ToRad(lat2)/2+Math.PI/4)/Math.Tan(ToRad(lat1)/2+Math.PI/4));
if (Math.Abs(dLon) > Math.PI)
dLon = dLon > 0 ? -(2*Math.PI-dLon) : (2*Math.PI+dLon);
return ToBearing(Math.Atan2(dLon, dPhi));
}
public static double ToRad(double degrees)
{
return degrees * (Math.PI / 180);
}
public static double ToDegrees(double radians)
{
return radians * 180 / Math.PI;
}
public static double ToBearing(double radians)
{
// convert radians to degrees (as bearing: 0...360)
return (ToDegrees(radians) +360) % 360;
}
// verify against the website example
DegreeBearing(50.36389,-4.15694,42.35111,-71.04083);
这篇关于C#中2个纬度/经度点之间的方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:C#中2个纬度/经度点之间的方向
基础教程推荐
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
