我正确的拥有一个凸包。我做了一个简单的课来计算中心点和直径。有了这些中心点和直径,我想使用 c#GMAP.NET 画一个圆。 当我画一个圆或调试它时,我得到了错误的中心点。
public class SEC
{
public static PlaceOfInterest centerPoint;
public static double diameter;
public static void SmallestEnclosingCircle(List<PlaceOfInterest> hull)
{
FindSmallestAngle(hull[0], hull[1], hull);
PlaceOfInterest p = centerPoint;
double dia = diameter;
}
private static void FindSmallestAngle(PlaceOfInterest p1, PlaceOfInterest p2, List<PlaceOfInterest> hullPoints)
{
PlaceOfInterest k = null;
foreach (PlaceOfInterest p in hullPoints)
{
if (p != p1 && p != p2)
{
k = p;
break;
}
}
double smallestAngle = Calculation.CalculateAngle(p1, k, p2);
foreach (PlaceOfInterest h in hullPoints)
{
if (!h.Equals(p1) && !h.Equals(p2) && !h.Equals(k) && smallestAngle > Calculation.CalculateAngle(p1, h, p2))
{
k = h;
smallestAngle = Calculation.CalculateAngle(p1, k, p2);
}
}
if (smallestAngle > 90)
{
//diameter
centerPoint = Calculation.FindTheCenterPoint(p1, k, p2);
diameter = Calculation.PythagorasDistance(p2, p1);
}
else if (smallestAngle < 90 && Calculation.CalculateAngle(p1, p2, k) < 90 && Calculation.CalculateAngle(p2, p1, k) < 90)
{
//define the circle
centerPoint = Calculation.FindTheCenterPoint(p1, k, p2);
diameter = Calculation.PythagorasDistance(p1, p2) / Math.Sin(smallestAngle * Math.PI / 180);
}
else if (Calculation.CalculateAngle(p1, p2, k) > 90)
{
FindSmallestAngle(p1, k, hullPoints);
}
else if (Calculation.CalculateAngle(p2, p1, k) > 90)
{
FindSmallestAngle(p2, k, hullPoints);
}
}
}