Skip to content

Instantly share code, notes, and snippets.

@mgnisia
Created September 23, 2020 17:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgnisia/a63901819f8426dd9383a0e751808372 to your computer and use it in GitHub Desktop.
Save mgnisia/a63901819f8426dd9383a0e751808372 to your computer and use it in GitHub Desktop.
Transform 1D Index Notation to 3D Index notation in C++ / CPP
template<typename T>
std::array<T,3> index_3D(T index, T size) {
T x = index % size;
T tmp = (index - x) / size;
T y = tmp % size;
T z = (tmp - y) / size;
return std::array<T,3>{z,y,x};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment