c# - 当我尝试计算使用直径和中心点绘制圆的点时,我得到了奇怪的值
问题描述
这些是非常简单的输入,我从名为 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# - 如何在 C#/VSTO 中使用 XlCmdType.xlCmdTableCollection 为 Excel 数据模型连接指定表
- django - Django:通过比较第二个 OneToOne 相关模型的属性来获取第一个模型的对象
- azure - Azure Terraform 自动化计划
- java - 如果 Child 类使用 Builder 模式,Parent 类是否必须使用 Builder 模式?
- r - R Shiny:使用 slickR 的图像的相对大小
- ios - 如何在 Objective C iOS 中发送 GET 请求并读回响应
- apache-kafka - 汇流槽连接器 - 多少就是太多
- flutter - 应用程序崩溃和图像选择器在颤动中无法正常工作
- c# - Blazor WebAssembly PWA 在 DevOps Pipeline 中失去了功能和风格
- pine-script - 我无法绘制这个简单的公式