C#-创建点组
如何创建接受一个点和所有点的列表并返回与原始点或足够接近的点的列表的对象 如果你还是听不懂我的话,这是一张照片: 我试过:C#-创建点组,c#,coordinates,cluster-analysis,point,C#,Coordinates,Cluster Analysis,Point,如何创建接受一个点和所有点的列表并返回与原始点或足够接近的点的列表的对象 如果你还是听不懂我的话,这是一张照片: 我试过: int range = 6; public List<IntPoint> getClosePoints(ref Dictionary<IntPoint,bool> allPoints,IntPoint startingPoint) { List<IntPoint> closePoints = new Li
int range = 6;
public List<IntPoint> getClosePoints(ref Dictionary<IntPoint,bool> allPoints,IntPoint startingPoint) {
List<IntPoint> closePoints = new List<IntPoint>();
closePoints.Add(startingPoint);
bool gotBigger = true;
while (gotBigger) {
gotBigger = false;
foreach (IntPoint proven in closePoints.ToList()) {
foreach (IntPoint possible in allPoints.Keys.ToList()) {
if (isInRange(proven,possible,range) && !allPoints[possible]) {
gotBigger = true;
closePoints.Add(possible);
allPoints[possible] = true;
}
}
}
}
return closePoints;
}
public bool isInRange(IntPoint A, IntPoint B, int range){
if(A.DistanceTo(B) < range)
return true;
return false;
}
int范围=6;
公共列表getClosePoints(参考字典allPoints、IntPoint startingPoint){
列表关闭点=新列表();
关闭点。添加(起始点);
bool-gotbeger=true;
while(更大){
gotbeger=false;
foreach(在closePoints.ToList()中证明的IntPoint){
foreach(在allPoints.Keys.ToList()中可能有IntPoint){
if(isInRange(已验证、可能、范围)&&!所有点[可能]){
gotbeger=true;
关闭点。添加(可能);
所有点[可能]=真;
}
}
}
}
返回关闭点;
}
公共布尔值范围(点A、点B、点范围){
如果(A.距离到(B)<范围)
返回true;
返回false;
}
(IntPoint
类似于Point
,它来自a区域
,所有点都有bool
值false)
但考虑到我的程序被称为千次循环,这使得我的程序超级滞后。:/(而且现在似乎不起作用了)试试这个:
public IEnumerable<Point> GetPoints(Point origin, IEnumerable<Point> points, int distance)
{
var result = new HashSet<Point>();
var found = new Queue<Point>();
found.Enqueue(origin)
while(found.Count > 0)
{
var current = found.Dequeue();
var candidates = points
.Where(p => !result.Contains(p) &&
p.Distance(current) <= distance);
foreach(var p in candidates)
{
result.Add(p);
found.Enqueue(p)
}
}
return result;
}
public IEnumerable GetPoints(点原点、IEnumerable点、整数距离)
{
var result=new HashSet();
var found=新队列();
已找到。排队(原点)
while(found.Count>0)
{
var current=found.Dequeue();
候选变量=点数
.Where(p=>!result.Contains(p)&&
p、 距离(当前)尝试以下方法:
public IEnumerable<Point> GetPoints(Point origin, IEnumerable<Point> points, int distance)
{
var result = new HashSet<Point>();
var found = new Queue<Point>();
found.Enqueue(origin)
while(found.Count > 0)
{
var current = found.Dequeue();
var candidates = points
.Where(p => !result.Contains(p) &&
p.Distance(current) <= distance);
foreach(var p in candidates)
{
result.Add(p);
found.Enqueue(p)
}
}
return result;
}
public IEnumerable GetPoints(点原点、IEnumerable点、整数距离)
{
var result=new HashSet();
var found=新队列();
已找到。排队(原点)
while(found.Count>0)
{
var current=found.Dequeue();
候选变量=点数
.Where(p=>!result.Contains(p)&&
p、 距离(当前)这是一个聚类问题
让所有的点接近你的输入点
将所有的点添加到一个Hashset中
现在将Hashset中的所有点放入一个队列并转到步骤1
当您的哈希集与上一次迭代相同时中断。您已找到所有正确的点
这是一个聚类问题。通过简单的步骤
让所有的点接近你的输入点
将所有的点添加到一个Hashset中
现在将Hashset中的所有点放入一个队列并转到步骤1
当您的哈希集与上一次迭代相同时中断。您已找到所有正确的点
显示您尝试过的内容。@sbouaked它们必须在2个单位的范围内。无论它们在该范围内有多远。天哪……我的眼睛……您是否有内存限制,我可以想出一个快速高效的CPU解决方案,但它需要大量内存。通过将点列表扩展到int[,]可以使用一些类似孤岛计数的算法applied@Luiso为什么要删除以前的答案?显示您尝试过的内容。@sbouaked它们必须在2个单位的范围内。不管它们在该范围内有多远。天哪……我的眼睛……您有内存限制吗,我可以想出一个快速的CPU效率解决方案n、 但这需要大量内存才能工作。通过将点列表扩展为int[,]数组,可以实现一些类似孤岛计数的算法applied@Luiso你为什么删除以前的答案?