Search In
• More options...
Find results that contain...
Find results in...

# Reversing an ordinal assignment

## 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,...)`

##### 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 << || (z << 16)

x = (o >> 0) & 7

y = (o >> & 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

##### 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...)

## 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.

×   Pasted as rich text.   Restore formatting

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

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

×

• ### Posts

• The version you are using is no longer supported on this forum. Please update to a modern version of Minecraft to receive support. Currently supported versions are 1.19 (Latest) and 1.18.2 (LTS).
• Use https://www.curseforge.com/minecraft/mc-mods/spark to create a profile.
• The version you are using is no longer supported on this forum. Please update to a modern version of Minecraft to receive support. Currently supported versions are 1.19 (Latest) and 1.18.2 (LTS).
• Hello, Can you help me for this error please, For information, I do not speak English, I am French. But, you can answer me in English, I will use a translator. Thank Exception message: java.lang.RuntimeException: Attempted to load class net/minecraft/client/gui/screen/Screen for invalid dist DEDICATED_SERVER Main().class NewGui().class

• 1
• 1
• 1
• 7
• 0
• ### Who's Online (See full list)

×

• #### Activity

×
• Create New...