首页 > 解决方案 > 当我尝试计算使用直径和中心点绘制圆的点时,我得到了奇怪的值

问题描述

这些是非常简单的输入,我从名为 Crystal-Pierce 的算法中得到了正确的中心点和直径。中心点0,0直径2.82 ...。最终目标是在 GmapController 上使用它来绘制圆,当我尝试使用结果时,它并没有包围所有凸包点。想着这个会画在地图上,我有没有考虑其他因素?比如放大多少 GMAP?

输入

1,1
1,-1
-1, -1
-1, 1

这是我得到的结果

Lat: 0|| Lon: 0|| diameter: 2.82842712474619
a: 1.4142135623731 || b: 0
a: 1.34499702392791 || b: 0.437016024448821
a: 1.14412280563537 || b: 0.831253875554907
a: 0.831253875554907 || b: 1.14412280563537
a: 0.437016024448821 || b: 1.34499702392791
a: 8.65956056235493E-17 || b: 1.4142135623731
a: -0.437016024448821 || b: 1.34499702392791
a: -0.831253875554907 || b: 1.14412280563537
a: -1.14412280563537 || b: 0.831253875554907
a: -1.34499702392791 || b: 0.437016024448821
a: -1.4142135623731 || b: 1.73191211247099E-16
a: -1.34499702392791 || b: -0.437016024448821
a: -1.14412280563537 || b: -0.831253875554907
a: -0.831253875554907 || b: -1.14412280563537
a: -0.437016024448821 || b: -1.34499702392791
a: -2.59786816870648E-16 || b: -1.4142135623731
a: 0.437016024448821 || b: -1.34499702392791
a: 0.831253875554907 || b: -1.14412280563537
a: 1.14412280563537 || b: -0.831253875554907
a: 1.34499702392791 || b: -0.437016024448821

这是循环的代码

static void Main (string[] args) {
            PlaceOfInterest p1 = new PlaceOfInterest (1, 1, 1, "");
            PlaceOfInterest p2 = new PlaceOfInterest (1, 1, -1, "");
            PlaceOfInterest p3 = new PlaceOfInterest (1, -1, 1, "");
            PlaceOfInterest p4 = new PlaceOfInterest (1, -1, -1, "");
            PlaceOfInterest p5 = new PlaceOfInterest (1, 0, 0, "");
            // PlaceOfInterest p6 = new PlaceOfInterest (1, 2, 2, "");
            List<PlaceOfInterest> list  = new List<PlaceOfInterest>();
            list.Add(p1);
            list.Add(p2);
            list.Add(p3);
            list.Add(p4);
            list.Add(p5);
             // list.Add(p6);
            List<PlaceOfInterest> hull = new List<PlaceOfInterest>();
            hull = ConvexHull.GrahmConvexHull(list);
            SEC.SmallestEnclosingCircle(hull);
            double x = SEC.centerPoint.Latitude;
            double y = SEC.centerPoint.Longitude;
            double diameter = SEC.diameter;
            Console.WriteLine("Lat: {0}|| Lon: {1}|| diameter: {2}", x, y, diameter);
            int segments = 20;

            double seg = Math.PI * 2 / segments;
            double aspect = 1;
            for (int i = 0; i < segments; i++)
            {
                double theta = seg * i;
                double radius = SEC.diameter / 2;
                double a = SEC.centerPoint.Latitude + Math.Cos(theta) * radius* aspect;
                double b = SEC.centerPoint.Longitude + Math.Sin(theta) * radius;
                Console.WriteLine("a: {0} || b: {1}", a,b);
            }



        }

标签: c#algorithmgeometrygmap.net

解决方案


推荐阅读