可以使用嵌套循环来生成其他的点。假设给定的点位置为(x, y),行和列的数量分别为rows和cols,间距为spacing。

首先,确定起始位置的x和y坐标,即左上角的点。由于考虑正负,起始位置的x坐标为x - (cols - 1) * spacing / 2,y坐标为y + (rows - 1) * spacing / 2。

然后,使用嵌套循环遍历所有的行和列,生成其他的点。内层循环控制列,外层循环控制行。在每次循环中,根据当前的行和列计算出相应的点的坐标。

下面是一个示例代码:

int x = 0; // 给定点的x坐标
int y = 0; // 给定点的y坐标
int rows = 3; // 行的数量
int cols = 4; // 列的数量
int spacing = 10; // 间距

int startX = x - (cols - 1) * spacing / 2; // 起始位置的x坐标
int startY = y + (rows - 1) * spacing / 2; // 起始位置的y坐标

for (int row = 0; row < rows; row++)
{
    for (int col = 0; col < cols; col++)
    {
        int pointX = startX + col * spacing; // 当前点的x坐标
        int pointY = startY - row * spacing; // 当前点的y坐标

        // 输出当前点的坐标
        Console.WriteLine("Point {0}: ({1}, {2})", row * cols + col + 1, pointX, pointY);
    }
}

运行上述代码,将会生成以下的点坐标:

Point 1: (-15, 15)
Point 2: (-5, 15)
Point 3: (5, 15)
Point 4: (15, 15)
Point 5: (-15, 5)
Point 6: (-5, 5)
Point 7: (5, 5)
Point 8: (15, 5)
Point 9: (-15, -5)
Point 10: (-5, -5)
Point 11: (5, -5)
Point 12: (15, -5)
``

原文地址: http://www.cveoy.top/t/topic/h5mc 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录