我想将圈数除以3个部分,并检查每个部分是否有点..这里的代码,但我不知道怎么检查?
int[] x = new int[3];
int[] y = new int[3];
for (int p = 0; p < Points.Count; p++ )
{
Point po =(Point)points[p];
for (int i = 1; i <= 3;i++ )
{
double angle = i * (360 / 3);
x[i] = (int)(po.x + iTransmissionRadius * Math.Cos(convertToRadians(angle)));
y[i] = (int)(po.y + iTransmissionRadius * Math.Sin(convertToRadians(angle)));
}
}
答案 0 :(得分:0)
这是你要的吗?
class Program
{
static Random rnd=new Random();
static void Main(string[] args)
{
var points=new List<Point>();
for(int i=0; i<100; i++)
{
points.Add(new Point(rnd.Next(100), rnd.Next(100)));
}
int iTransmissionRadius=6;
var neighbors=FindClosestPoints(points).ToArray();
// count = 100
var has_neighbors_within_radius=neighbors.Zip(points, (A, B) => AreWithinRadius(A,B,iTransmissionRadius)).ToArray();
// true or false if there is neighbor closer than radius
}
static double DistanceBetweenPoints(Point A, Point B)
{
return Math.Sqrt((A.X-B.X)*(A.X-B.X)+(A.Y-B.Y)*(A.Y-B.Y));
}
static bool AreWithinRadius(Point A, Point B, int radius)
{
return DistanceBetweenPoints(A,B)<=radius;
}
static IEnumerable<Point> FindClosestPoints(IEnumerable<Point> points)
{
return points.Select((A) =>
{
var list=points.ToArray();
Array.Sort(list, (B,C)=> DistanceBetweenPoints(A,B).CompareTo(DistanceBetweenPoints(A,C)));
return list.Skip(1).FirstOrDefault();
});
}
}