Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 动态邻域坐标_C#_Coordinates_Generator_Points - Fatal编程技术网

C# 动态邻域坐标

C# 动态邻域坐标,c#,coordinates,generator,points,C#,Coordinates,Generator,Points,对于图像过滤器,我想生成一个可变的邻域。 这就是我的社区目前的样子,它是摩尔社区 private Point[] neighborhood = new Point[] { new Point(-1,-1),

对于图像过滤器,我想生成一个可变的邻域。 这就是我的社区目前的样子,它是摩尔社区

private Point[] neighborhood = new Point[]
                                               {
                                                   new Point(-1,-1),
                                                   new Point(0,-1),
                                                   new Point(1,-1),

                                                   new Point(-1,0),
                                                   new Point(1,0),

                                                   new Point(-1,1), 
                                                   new Point(0,1), 
                                                   new Point(1,1), 
                                               };
当我想改变社区的大小时,这会变得相当复杂。 我想要一个返回所有坐标的函数,比如generateNeighborhood(8)将返回这个点数组。最好的方法是什么?

类似的方法

private Point[] GetNeighbors(int count)
{
    int a, x, y, c = count / 2;
    Point[] p = new Point[count * count];

    for (a = y = 0; y < count; y++)
        for (x = 0; x < count; x++)
            p[a++] = /* Create point here */
    return p;
}
private Point[]获取邻居(整数计数)
{
int a,x,y,c=计数/2;
点[]p=新点[计数*计数];
对于(a=y=0;y

我认为您可以添加缺少的代码;)

为什么使用:int a,x,y,c=count/2;?变量c表示中心坐标,因此可以计算当前坐标和去中心坐标之间的差值(增量;)等我需要坐标时再做。对于(a=y=0;y新的点(x-c,y-c),仅此而已!