我试图在地球表面的某个点周围画一个正方形.
我正在使用从here和here检索到的信息,最终想出了这个: –
// Converting degrees to radians
double latInDecimals = (Math.PI / 180) * latitude;
double longInDecimals = (Math.PI / 180) * longitude;
List<string> lstStrCoords = new List<string>();
double changeInLat;
double changeInLong;
double lineOfLat;
// Calculating change in latitude for square of side
changeInLong = (side / 1000) * (360.0 / 40075);
// Calculating length of longitude at that point of latitude
lineOfLat = Math.Cos(longitude) * 40075;
// Calculating change in longitude for square of side 'side'
changeInLat = (side / 1000) * (360.0 / lineOfLat);
// Converting changes into radians
changeInLat = changeInLat * (Math.PI / 180);
changeInLong = changeInLong * (Math.PI / 180);
double nLat = changeInLat * (Math.Sqrt(2) / 2);
double nLong = changeInLong * (Math.Sqrt(2) / 2);
double coordLat1 = latInDecimals + nLat;
double coordLong1 = longInDecimals + nLong;
double coordLat2 = latInDecimals + nLat;
double coordLong2 = longInDecimals - nLong;
double coordLat3 = latInDecimals - nLat;
double coordLong3 = longInDecimals - nLong;
double coordLat4 = latInDecimals - nLat;
double coordLong4 = longInDecimals + nLong;
// Converting coords back to degrees
coordLat1 = coordLat1 * (180 / Math.PI);
coordLat2 = coordLat2 * (180 / Math.PI);
coordLat3 = coordLat3 * (180 / Math.PI);
coordLat4 = coordLat4 * (180 / Math.PI);
coordLong1 = coordLong1 * (180 / Math.PI);
coordLong2 = coordLong2 * (180 / Math.PI);
coordLong3 = coordLong3 * (180 / Math.PI);
coordLong4 = coordLong4 * (180 / Math.PI);
现在即使这样,我加入的多边形也是一个矩形.
我对我的代码有什么问题感到困惑.
解决方法:
除非球座位于赤道上,否则球体上一个纬度和经度的矩形长度不同于km.它朝着两极走得更窄.如果你想让双面都相同,你必须进行修正
longitudinal_length = latitudinal_length / cos(latitude)
因此,您需要将您的平方纵向长度除以cos(纬度).
现在,您的广场可能仍然是弯曲的,但这取决于地图的投影方式,这是一个完全不同的故事.您需要知道Google使用的投影公式进行更正.
您可能会发现更复杂的公式,考虑到地球不是一个完美的球体这一事实,但我认为这应该足以满足您的位置标记.另请注意,在/ -90度时,您将得到零除.因此,在杆上放置一个矩形需要另一种方法.
来自:IBM Knowledge Center/Geographic coordinate system /图4.刻度上位置之间的不同尺寸
标签:c,geometry,polygon 来源: https://codeday.me/bug/20190625/1286959.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。