# Index to 2D coordinates

This topic is 2927 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

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 10
• 11
• 13
• 9
• 9
• ### Forum Statistics

• Total Topics
634081
• Total Posts
3015396
×