Sign in to follow this  

get XYZ values from one-dimensional array

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this