#x, y, and z offsets from a single number
1 messages Β· Page 1 of 1 (latest)
I start off with a single block, which is the origin. If i input the number 0, it should return the origin coords, (0, 0, 0)
If i enter the numbers 1-26, it'll go over a list of blocks that surround the origin. For example:
1 -> 1, 0, 0
2 -> 1, 0, -1
3 -> 1, 0 1
4 -> 1, -1, 0
... and so on until all blocks around the origin have been covered
Then, when I reach number 27, it should start searching the next "layer". For example:
27 -> 2, 0, 0
28 -> 2, 0, -1
29 -> 2, 0, -2
.. and so on
I want this to repeat until it searches all blocks within a 20x20x20 cube around the origin
Here's what I mean by layer
If I have a 10x10x10 cube
ok
each "layer" would be considered each inner cube within it. For example, layer 1 is the 1x1x1 cube in the middle. Layer 2 is the 3x3x3 cube surrounding the middle cube
and so on
ok thats quite simple.
forget to start that you are in 3d. simplify it to 2d for an algorithm
what I'm trying to do here is make a steppable algorithm, each step would check one block of this large 20x20x20 cube
BUT it is important that it starts searching from the origin first
yes
I did somethign similar with java final static List<Coord> cardinal = Arrays.asList( new Coord(0, 1), new Coord(1, 0), new Coord(0, -1), new Coord(-1, 0) ); final static List<Coord> ordinal = Arrays.asList( new Coord(1, 1), new Coord(1, -1), new Coord(-1, -1), new Coord(-1, 1) );
Coord being offsets
Isnβt that only for blocks surrounding a single block
yes, but that is what you are doing, at its base
wha t you want to do is first get all the surounding blocks
then you want to do the same but multiply the offset
and so on until you have reached 20
so for (Coord direction : cardinal) {
no you take each Coord and multiply it
even then that wouldn't reall ywork-
π₯β¬π₯β¬π₯
β¬π₯π₯π₯β¬
π₯π₯π₯π₯π₯
β¬π₯π₯π₯β¬
π₯β¬π₯β¬π₯
you can choose to do cardinal/ordinal or both at teh same time
all the red squares are the blocks checked using your system
the black ones are still being missed
then your implementation is incorrect
this is how im processing it in my head
oh I see what you mean
it will
and it'll miss more the further it checks
yep, in which case
um, thinking
ok we can do it still using offsets,
just from cardinals
cardinal directions N,S,E,W. Ordinals are NE, SE, SW, NW
oh
so we have to search 1 to 20
i feel like this should be a stackoverflow question lmao
hm wait so i'm thinking
if input is 0, the layer is 0
if the input is less than or equal to 9, the layer is 1
so for step1 we do origin + each cardinal. From each cardinal we also grab the cardinal + the inverse of the cardinal times teh step
if the input is less than or equal to 25, the layer is 2
ok a layer at a time
so starting with List<Coord> cardinal = Arrays.asList( new Coord(0, 1), new Coord(1, 0), new Coord(0, -1), new Coord(-1, 0) );
origin + each cardinal. each cardinal + its rotation. so cardinal (0,1) would become (0,1) + (1,0)
isn't that just checking the oridnal as well then
by the wait i dont mind of the algorithm searches starting from ordinals
but doing it that way you can repeate teh offset/rotation multiplied per step so you can walk the line
i just want the closest layer to be searched first
let me see if I can throw some code down
alright
@vocal mist i got something
public StepResult step() {
Vec3 offset = new Vec3(0, 0, 0);
System.out.println("currentStep: " + currentStep);
int layer = 1;
while (currentStep > Math.pow(layer, 2)) {
layer += 2;
}
System.out.println(" layer: " + layer);
System.out.println(" offset: " + offset);
currentStep++;
return StepResult.PROGRESS;
}
Mines still writing
currentStep: 1
layer: 1
offset: (0, 0, 0)
currentStep: 2
layer: 3
offset: (0, 0, 0)
currentStep: 3
layer: 3
offset: (0, 0, 0)
currentStep: 4
layer: 3
offset: (0, 0, 0)
currentStep: 5
layer: 3
offset: (0, 0, 0)
currentStep: 6
layer: 3
offset: (0, 0, 0)
currentStep: 7
layer: 3
offset: (0, 0, 0)
currentStep: 8
layer: 3
offset: (0, 0, 0)
currentStep: 9
layer: 3
offset: (0, 0, 0)
currentStep: 10
layer: 5
offset: (0, 0, 0)
It doesn't print the correct layer number or offset yet
but it can at least distinguish different layers apart
ok well adding layer = (layer / 2) + 1; underneath the while loop made it print the correct layer
ok I think I have teh basis for finding teh adjacent coords
nothign for layers yet
that should allow you to call findCoords(new Coord(0,0), 10) and it will return you all Coords around the origin up to 10 steps out
will this work for steps greater than 10 too?
wait but this fully working for a 2d plane?
it should be yes
brb dog out
although i still need to input a single number and get a single set of coords as output
back
Yep, you specify how far out you want your surrounding coords to be
but using that you can easily do that by layer
?
like you immediately process all the coordinates, then if i want a specific single number i just index the result list?
if you call that method with a distance of 1 you would get back a Set containing 9 Coords
yeah but like thats not what i was rlly looking for
for example if I input the number "2" it would give me the second coord
and the distance is already assumed to be 20, set by a constant
2 as in the second layer?
I'm not understanding
you said you wanted to get all teh surrounding Coords around an origin going out to 20 distance.
then the layer above and below
did you see this
why 1-26 if you are searching to a 20x20x20?
how is 26 the first layer if your max range is 20?
there are 27 blocks in a 3x3 cube
by max range of 20, I meant the whole cube to search is 20x20x20
ah, onion layers
well thats a little haarder as you have no way of prioritizing which coords to include below a full layer
you can easily specify the layer you want
is there a reason you want ot be able to request partial layers 1-25?
what do you mean request
if you input 20 you would not be getting a full layer
i mean
The simplest is 0 = just the origin, 1 = the layer surrounding the origin and so on.
the point is that i get a single coord set from a single number
and the coords returned from numbers 1-26 should be a full layer
well yes thats what im doing, except one block at a time
oh ok so it doesn;t matter what you typed, be it 1 or 26 you would get teh same number of Coords back
I'm determining the layer from the block number
I'm always getting 1 coord
For example inputting the number 0 would give me the origin, (0, 0, 0)
inputting the number 1 would give me (-1, -1 , -1)
inputting the number 2 would give me (-1, -1, 0)
ok there you are not making sense again
etc, until the first layer is complete
lmfao ok look
the layer is not input from the client's end
you are saying you want individual coords
its an internal variable to figure out the block
a specific block
then you have to decide on a search pattern
and not so easy
yeah
but im going for it
this is what I've got right now
it's for 2D planes right now, don't mind the Y coordinate in Vec3
well to calculate what layer its on just cubroot the value (round down)
from there its just how you search for teh block
if you always move -1,-1,-1 from origin to get to teh layer
cuberoot of 27 is 3
which would be the first block in the 3rd layer
origin being counted as a layer
int layer = (int) Math.cbrt(currentStep);?
because it aint working
layer 3 should begin at step 27
doesnt casting to int do the same thing for positive numbers
not sure
but you don;t want it rounded up
well now it's all layer 1
oh nvm 27 is layer 3
i didn't realize that you're still doing it for 2D plane
when you said cube root i assumed u were doing 3d
yes, that is for 3d
but its saying layer 1 at step 7
um
and it goes to layer 2 at step 8
well now step 8 is layer 2 and step 9 is layer 3
yeah, my head spinning
this is breaking my brain
int sideLength = 1;
while (currentStep > Math.pow(sideLength, 3)) {
sideLength += 2;
}
int layer = (sideLength / 2) + 1;
what I have here works
there must be a cleaner way
6*SideLength^2
sorry squared
surface area is 6 * (length * length)
which is how many blocks in each layer
wait so what do i assign to layer
so far i managed to find the layer and the position in each layer
and the maximum position for each layer
trying to tink of a simple way to calculate teh layer
we shoudl be able to do it without the while
if you can figure something out sure
I'm losing brain cells though and I might attempt it later
Same here π
anyways
now i have 3 bits of information
layer, position within the layer, maximum position within the layer
now i just have to convert that into an offset
holy shit
i think i got something
but its hard to tell if its even working correctly
it might
now i just need to figure out if this print output is correct
im just gonna place the blocks in minecraft and see if it works
no its wrong
Yeah your code isn;t getting the layer right for me
step 27 should be in layer 2 and step 28 should be in layer 4currentStep: 27 layer: 4 position: 2 origin: (0, 0, 0) offset: (0, 0, 0) currentStep: 28 layer: 4 position: 3 origin: (0, 0, 0) offset: (0, 0, 0)
the layer is right but the offest is wrong
layer is wrong
you sure?
it shows 27 is in layer 4
did I copy your code wrong?
maybe?
public StepResult step() {
Vec3 offset = new Vec3(0, 0, 0);
System.out.println("currentStep: " + currentStep);
int sideLength = 1;
while (currentStep > Math.pow(sideLength, 2)) {
sideLength += 2;
}
int layer = (sideLength / 2) + 1;
System.out.println(" layer: " + layer);
int position = currentStep - (int) Math.pow(sideLength - 2, 2);
System.out.println(" position: " + position);
System.out.println(" origin: " + origin + " offset: " + offset);
currentStep++;
return StepResult.PROGRESS;
}```
hmm
ah I see you changed the pow
oh yeah
im trying to solve the 3d thing rn
this is what i have right now
the y and z are wrong though
im so close
position seems right to me
layer: 2
position: 26
origin: (0, 0, 0) offset: (0, 0, 0)
currentStep: 28
layer: 3
position: 1
origin: (0, 0, 0) offset: (0, 0, 0)```
yeah it works
26 blocks in layer 2
im just stuck on converting it into an offset now
ah ok
btw the maxPosition is here too
i mean negative numbers is expected
its an offset it shoudl have half negative, half positive
yes, its all blocks around the origin
yes
oh thats what you meant
okay
i feel like im so close man
just the y and z coord
my brain is on overdrive rn
layer 2 pos 1 and layer 2 pos 4 have the same offset. one of those is negative where it should be positive
yeah i realized
honestly i cant do this rn
my brain is fried
im gonna play some video games and go back to this later
yeah you have to count the total blocks on each side to work out which plane the target block is on, then calculate the offset
i cant think properly rn lmao
YES
@vocal mist i got it finally
the break was very necessary
int position = currentStep > 1 ? currentStep - (int) Math.pow(sideLength - 2, 3) - 1 : 0;
int x = 0, y = 0, z = 0;
for (int i = 0; i < position; i++) {
z++;
if (z == sideLength) {
z = 0;
y++;
if (y == sideLength) {
y = 0;
x++;
}
}
// cause the loop to repeat one more time if all 3 values are not min or max
if (x != 0 && x != sideLength - 1 && y != 0 && y != sideLength - 1 && z != 0 && z != sideLength - 1) {
i--;
}
}
Vec3 offset = new Vec3(x - (sideLength / 2), y - (sideLength / 2), z - (sideLength / 2));