Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/145.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/11.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++ N维网格顶点计算_C++_Algorithm_Math - Fatal编程技术网

C++ N维网格顶点计算

C++ N维网格顶点计算,c++,algorithm,math,C++,Algorithm,Math,问题:给定单元格索引(红色),计算围绕单元格索引的数组索引(黑色)。 bool CalculateCellVerticesFromIndex(size_t index, size_t* vertices) { size_t gridSize[2] = {6, 5}; return true; // if the index was valid return false; // if the index was invalid } 计算已知大小(m X N X…)的N维

问题:给定单元格索引(红色),计算围绕单元格索引的数组索引(黑色)。

bool CalculateCellVerticesFromIndex(size_t index, size_t* vertices)
{
    size_t gridSize[2] = {6, 5};
    return true;  // if the index was valid
    return false; // if the index was invalid
}
计算已知大小(m X N X…)的N维网格中围绕单元的顶点

示例图:

int顶点[4]={0,0,0,0}


在上图中,计算CellVerticesFromIndex(12,顶点);应该用{14,15,20,21}填充顶点

似乎你需要阅读关于整数除法和取余数(模)的操作,这不是家庭作业。这是为了我的工作。嗯,我想你可能是对的,对不起,我的错。显然,我的大脑现在(或别的什么)有点混乱。我将删除我以前的评论……我们这个C OOC C++的方法签名出现C++,我希望STD::向量或STD::ARARY函数签名是C-ISH;但我试图不使用std::vector来向后兼容必须与之交互的遗留代码(即C)。如果您有一个解决方案可以使用std::vector或std::array,我也很乐意看到它。我以后可以自己翻译。我喜欢这段代码的方向,但是如果这是一个3D网格,甚至是一个4D网格,会发生什么呢?它将利用整数除法的相同原理。例如,要获得三维中的层编号,需要将索引除以二维的乘积
Width = 6
Row = Index div (Width - 1)
if Row > 5 - 2 then OutOfGrid
Column = Index mod (Width - 1)
LeftBottom = Row * Width + Column
LeftTop = LeftBottom + Width
RightBottom and RightTop - elaborate