Jump to content
  • Advertisement
Sign in to follow this  
VideroBoy

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.

If you intended to correct an error in the post then please contact us.

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. dry.gif

Share this post


Link to post
Share on other sites
Advertisement

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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!