Two-dimensional matrix for one measurement and vice versa

I tried to find information about converting an index that was converted from a two-dimensional index to one. Then return one index to 2-dimensional. I don’t even know what this method is called.

for a single index

  int index = x + y * width;
   MyArray[index] ;

So my question is how to get it back in two dimensions?

int x = index ??? width;
int y = index ??? width;

For some reason I can't wrap my head around me.

thank

+5
source share
2 answers
int x = index % width;
int y = index / width;
+7
source

x = index% width; y = index / width;

+3
source

All Articles