# Index to 2D coordinates

This topic is 2715 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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.

##### Share on other sites

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.

x=index % width
y=index/width

• 10
• 48
• 12
• 10
• 10
• ### Forum Statistics

• Total Topics
631383
• Total Posts
2999681
×