Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Reversing an ordinal assignment


Yagoki
 Share

Recommended Posts

This problem is more of a mathsy one that a forge one but it's been bugging me for so long now that I think I am incapable of noticing the solution

 

Let's say I have an integer set of coordinates, each ranging from 0 to some independent finite limit (which may be different for each. This can be thought of as an N dimensional grid with coordinates

(i, j, k, ...)

and lengths

(I, J, K, ...)

. In this case each coordinate that can be occupied/intersect of the grid can be counted with an ordinal assigned by

o=i+j*I+k*I*J+...

. this is useful wen trying to assign a metadata value or some such. The problem I'm having is figuring out a way of reversing this operation to get the original

(i,j,k,...)

given the ordinal and

(I,J,K,...)

Link to comment
Share on other sites

Thats a dense, yet slow way of indexing things typically people just set bit ranges for certian things:

o = (x << 0) | (y << 8) || (z << 16)

x = (o >> 0) & 7

y = (o >> 8) & 7

z = (o >> 16) & 7

 

But you way it's similiar but can't easily do the shifts.

So:

o = x+y*(X)+z*(X*Y)

x = o % X

y = floor((o % (X*Y))/X)

z = floor((o % (X*Y*Z))/(X*Y))

 

Complicated and ugly, but should do what you want.

 

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Patreon: http://www.patreon.com/lexmanos
Paypal: http://paypal.me/LexManos

BitCoin: 1Q8rWvUNMM2T1ZfDaFeeYQyVXtYoeT6tTn

Link to comment
Share on other sites

Thanks, that's been bugging be for ages. think I'd just looked at it for too long to notice as I said. Did initially think of just packing like you say but it wound up being important that they remain in order and without gaps (various rng operations etc...)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.