如何使矩形的所有角都正交

问题描述 投票:0回答:1

我使用Arcobjects C#.Net在ArcGIS Desktop中开发了一个应用程序。应用程序将通过连接四个已知坐标创建一个矩形。我需要将所有四个角调整为正交(90度)。是否有任何数学方法可以从四个已知的坐标中实现这一目标?或者Arcobjects中是否有任何直接的方法来执行此操作?

enter image description here

c# geometry mathematical-optimization arcobjects orthogonal
1个回答
3
投票

如果要确保角度为90度,则需要确保对角线长度相同。这意味着在您的示例中长度(P1-P3)==长度(P2-P4)。

您可以使用:midpoint =(P1-P3)的中间位置。这是你的中心点。现在将虚线平行移向中点。现在你已经调整了P2和P4,穿过圆圈和虚线。

enter image description here

在代码中:

static void Main(string[] args)
    {
        Point P1 = new Point() { X = 2, Y = 1 };
        Point P2 = new Point() { X = 1.8, Y = 2.5 };
        Point P3 = new Point() { X = 6, Y = 4 };
        Point P4 = new Point() { X = 6.2, Y = 2.6 };
        double distX13 = P3.X - P1.X;
        double distY13 = P3.Y - P1.Y;
        Point midP = new Point() { X = P1.X + distX13 / 2, Y = P1.Y + distY13 / 2 };
        double lenght13 = Math.Sqrt(distX13 * distX13 + distY13 * distY13);

        double a24 = Math.Atan2(P4.Y - P2.Y, P4.X - P2.X);

        P2.X = midP.X - Math.Cos(a24) * lenght13 / 2;
        P2.Y = midP.Y - Math.Sin(a24) * lenght13 / 2;
        P4.X = midP.X + Math.Cos(a24) * lenght13 / 2;
        P4.Y = midP.Y + Math.Sin(a24) * lenght13 / 2;


    }
© www.soinside.com 2019 - 2024. All rights reserved.