问题:给定一个单元格索引(红色)计算单元格索引周围的数组索引(黑色)。
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 vertices[4] = {0, 0, 0, 0}
在上图中,CalculateCellVerticesFromIndex(12, vertices);应该用 {14, 15, 20, 21} 填充顶点;
最佳答案
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
关于c++ - N维网格顶点计算,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10051426/