C# 围绕一个长点画一个正方形

C# 围绕一个长点画一个正方形,c#,geometry,polygon,C#,Geometry,Polygon,我试图在地球表面的一个给定点周围画一个正方形 我正在使用从中检索到的信息,并最终得出以下结论:- // Converting degrees to radians double latInDecimals = (Math.PI / 180) * latitude; double longInDecimals = (Math.PI / 180) * longitude; List<string> lstStrCoords

我试图在地球表面的一个给定点周围画一个正方形

我正在使用从中检索到的信息,并最终得出以下结论:-

        // 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);
//将度转换为弧度
双拉丁小数=(Math.PI/180)*纬度;
双纵标=(Math.PI/180)*经度;
List lstStrCoords=新列表();
双变嵌体;
双变长;
双线照明;
//计算边长平方的纬度变化
变更长度=(侧面/1000)*(360.0/40075);
//计算那个纬度点的经度长度
lineOfLat=数学Cos(经度)*40075;
//计算“side”边平方的经度变化
changeInLat=(侧面/1000)*(360.0/一线);
//将变化转换为弧度
changeInLat=changeInLat*(Math.PI/180);
changeInLong=changeInLong*(Math.PI/180);
双nLat=changeInLat*(数学Sqrt(2)/2);
双长度=变化长度*(数学Sqrt(2)/2);
双坐标1=拉丁小数+nLat;
双坐标长1=纵向椭圆+长;
双坐标2=拉丁小数+nLat;
double coordLong2=纵向CIMALS-nLong;
双坐标3=拉丁小数-nLat;
double coordLong3=纵向CIMALS-nLong;
双坐标4=拉丁小数-nLat;
双坐标长4=纵向椭圆+长;
//将坐标转换回度
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);
现在,即使这是可行的,我通过连接它们得到的多边形是一个矩形


我不知道我的代码出了什么问题。

球体上一个纬度和经度为1度的矩形,除非位于赤道上,否则其长度(以千米为单位)并不相同。它向两极的方向越来越窄。如果你想使两边的尺寸相同,你必须进行修正

longitudinal_length = latitudinal_length / cos(latitude)
因此,您需要将正方形的纵向长度除以
cos(纬度)

现在,你的正方形可能仍然是弯曲的,但这取决于地图的投影方式,这是一个完全不同的故事。你需要知道谷歌用来修正的投影公式

你可能会发现更复杂的公式,考虑到地球不是一个完美的球体这一事实,但我认为这对于你的位置标记应该足够了。还要注意的是,在+/-90度时,你会得到一个零的除法。因此,将矩形放置在柱上需要另一种方法



摘自://图4。分划上不同位置之间的不同尺寸

谢谢,我将尝试此方法并让您知道。我之所以不担心地球的曲率,是因为我正在创建的正方形非常小——3米。@AbijeetPatro——不管你的矩形有多小。在60度纬度,如果不使用此校正,纵向长度将始终是横向长度的两倍。是的,纵向线都在两极相交,在赤道处有一个最大距离。因此,例如,如果我在地球表面60度,我的纬度长度是x,那么我的纵向长度将是2x?我之前评论中的链接不再有效。因此,我在回答中添加了一个图像。