我正在尝试实现所提出的关于在距线的给定垂直距离上找到一个点的方程here。不幸的是,我收到的线路不直。这是由于我将Lat / long与常规x / y坐标混合还是我做了别的错误?!
double distPoint = 0.02;
double latDiff = temp2.Latitude - temp.Latitude;
double longDiff = temp2.Longitude - temp.Longitude;
double length = Math.Sqrt(latDiff * latDiff + longDiff * longDiff);
double uLat = latDiff / length;
double uLong = longDiff / length;
double newLat1 = temp2.Latitude + (distPoint / 2) * uLat;
double newLong1 = temp2.Longitude - (distPoint / 2) * uLong;
double newLat2 = temp2.Latitude - (distPoint / 2) * uLat;
double newLong2 = temp2.Longitude + (distPoint / 2) * uLong;
现在更改了代码和变量名称。仍然收到错误: - (
double dist = 0.02;
double latDiff = secondTestPoint.Latitude - firstTestPoint.Latitude;
double longDiff = secondTestPoint.Longitude - firstTestPoint.Longitude;
double length = Math.Sqrt(latDiff * latDiff + longDiff * longDiff);
double uLat = latDiff / length;
double uLong = longDiff / length;
double newLat1 = secondTestPoint.Latitude + (dist / 2) * uLong;
double newLong1 = secondTestPoint.Longitude - (dist / 2) * uLat;
double newLat2 = secondTestPoint.Latitude - (dist / 2) * uLong;
double newLong2 = secondTestPoint.Longitude + (dist / 2) * uLat;
以下是变量值:
latDiff = -0.0046187639236450195
longDiff = -0.0058203935623168945
length = 0.0074303405980227239
uLat = -0.62160864131505777
uLong = -0.78332796263279647
newLat1 = 58.39273776863341
newLong1 = 15.558675147558933
newLat2 = 58.408404327886061
newLong2 = 15.546242974732632
更新:我得出的结论是,故障是由于纬度/长度问题造成的。当它们实际上不是时,认为lat / long等于正方形会产生错误,这似乎是合理的。特别是在与北欧合作时。
答案 0 :(得分:1)
如此小的比例,x / y和纬度/经度之间的差异是不相关的。你做错了别的事;你应该拥有的是:
double distPoint = 0.02;
double latDiff = temp2.Latitude - temp.Latitude;
double longDiff = temp2.Longitude - temp.Longitude;
double length = Math.Sqrt(latDiff * latDiff + > longDiff * longDiff);
double uLat = latDiff / length;
double uLong = longDiff / length;
double newLat1 = temp2.Latitude + (distPoint / 2) * uLong;
double newLong1 = temp2.Longitude - (distPoint / 2) * uLat;
double newLat2 = temp2.Latitude - (distPoint / 2) * uLong;
double newLong2 = temp2.Longitude + (distPoint / 2) * uLat;
也就是说,向量(uLat, uLong)
是你线条方向的单位向量,所以垂直单位向量是(uLong, -uLat)
- 注意坐标交换位置,除了一个被否定之外。
答案 1 :(得分:0)
答案 2 :(得分:0)
在您链接的公式中,最后4行的乘法序列为:
[dy, dx, dy, dx]
==[uLong, uLat, uLong, uLat]
然而你已经使用过:
[dx, dy, dx, dy]
==[uLat, uLong, uLat, uLong]
你的最后4行应该是这样的:
double newLat1 = temp2.Latitude + (distPoint / 2) * uLong; //dy appears first
double newLong1 = temp2.Longitude - (distPoint / 2) * uLat; //then dx
double newLat2 = temp2.Latitude - (distPoint / 2) * uLong;
double newLong2 = temp2.Longitude + (distPoint / 2) * uLat;