• Advertisement
Sign in to follow this  

get XYZ values from one-dimensional array

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

I have a one dimensional array which represents size in 3D space, meaning like:

data[size * sizeY * size] ,where size is same for width/depth and sizeY is for height

When I want to change value in data[index], I do: index = (x * size) + (y * size * size) + z
and that works correctly

But I'm trying to get x, y and z value off the data[] with index value somewhere between 0 and (size*sizeY*size) but I'm not sure how I can get them.
This is what I've got so far for example:

x = 10
y = 20
z = 30
index = (x * size) + (y * size * size) + z
data[index] = some value

x = ? = 10
y = index / size / size = 20
z = ? = 30

How do I get the x and z from index?

Share this post


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

  • Advertisement