Created
September 23, 2020 17:56
-
-
Save mgnisia/a63901819f8426dd9383a0e751808372 to your computer and use it in GitHub Desktop.
Transform 1D Index Notation to 3D Index notation in C++ / CPP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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