Advertisement

Index to 2D coordinates

Started by January 13, 2011 02:45 AM
0 comments, last by JTippetts 13 years, 11 months ago
You know how you can represent a 2D array with a 1D array by converting the coordinates to an index, right?
index = x + (y * width)

Is it possible to do the opposite? Take an index and get the corresponding (x, y) coordinates?

Because if it is, I certainly haven't been able to figure it out. dry.gif

You know how you can represent a 2D array with a 1D array by converting the coordinates to an index, right?
index = x + (y * width)

Is it possible to do the opposite? Take an index and get the corresponding (x, y) coordinates?

Because if it is, I certainly haven't been able to figure it out. dry.gif


x=index % width
y=index/width

This topic is closed to new replies.

Advertisement