I can get the coördinates of the hexes quite easily, so the question is how to get the chunk that corresponds with that hex?
It’s probably possible with transforming the coördinates of the hex and checking which chunk is the closest to it, but I’ve actually no clue on how to do that.
Minor update:
If you know any articles et cetera, post them if possible. I prefer getting information, instead of codes!
Could you post with more information on what you are actually trying to do with the chunks. I feel like there isn’t enough description to know what you want. Make sure to describe your inputs and your expected output and what those types are.
First of all, thanks for the help, I will be try a little bit clearer this time
The idea basically is that I want to create an graph but instead of having horizontal and vertical axis, I want them to be slightly rotated to create a graph like the following graph: Image2:
If you place that graph over the current hexagonal chunks (image1), you will be able to see what I am trying to do: Image3:
And if you take a look at image2, you can see that Hex A is inside the boundary(DEFG) of Chunk (0, 0)
So basically what I am trying to do is creating a grid without “straight” axes. So I can locate the place of an hex inside the grid and simply use the Math.round() function to get the chunk of the hex.
But the problem I am facing is that I don’t know how to create this type of grid. I’ve been searching, but because I don’t know the proper name of it, the results are limited.
(I hope it is clearer now)
Thanks for reading, -Rose
Using A as an example, you want input to be 3,0 and you want output to be 1,0.
((3)*(2/3))/3 = 0.66666666666 (rounds to 1)
(((-(3))/3)+((sqrt(3)/3)*0))/3 = 0.33333333333 (rounds to 0)
Using B as an example, you want input to be -3,3 and you want output to be -1,1.
((-3)*(2/3))/3 = -0.66666666666 (rounds to -1)
(((-(-3))/3)+((sqrt(3)/3)*3))/3 = 0.91068360252 (rounds to 1)
Using C as an example you want input to be 0,-1 and you want output to be 0,0.
((0)(2/3))/3 = 0
(((-(0))/3)+((sqrt(3)/3)-1))/3 = -0.19245008973 (rounds to 0)
I also did some testing with chunks farther away, like if hex_ix = -12 and hex_iy =10 it will return -3,3 after rounding.Looks like you didn’t need any help after all, congrats.
Not sure what you need that crazy grid for when this solution that you posted works as is.
EDIT: Did more testing with CHUNK_SIZE and found a problem.
A bit of a special case if hex_ix = -3 and CHUNK_SIZE = 3 then the formula returns chunk_ix = -0.5 which rounds to 0 instead of -1. Problem here is that if hex_iy = -1 then chunk_ix would also = -1, but if hex_iy = 0 then chunk_ix rounding to 0 is fine. Problem is that the formula for chunk_ix doesn’t account for hex_ix at all. The formula for chunk_iy should be fine since it accounts for both hex_ix and hex_iy.
EDIT 2:
Cleaned up the image a bit, colour coded it, and added a circle. I feel like the solution probably involves trigonometry, but I haven’t figured it out yet. Will keep trying.
Wait a minute, isn’t the grid perceived? Wouldn’t the X axis fall along the same, defined, axis as you have made it? Same for Y?
It doesn’t seem like getting the next chunk should be an issue from a chunk.
Chunk[x+1,y]
Chunk[x,y+1]
You would just need to define the correct coordinates. That said it should be a perfect map, like displayed.
Although what I am thinking I see probably isn’t what you are trying to do.
Please define these terms…
chunk
hex
Are chunks the colored groupings of hexes?
What are you trying to do? What is your input data and what is your output data expected? ‘by this you can see this’ doesn’t tell me much. I think you are trying to take a hex out of a chunk of hexes and determine if a region contains the hex. Or use a region to find which hexes are contained inside the region. In this case, maybe you should rotate the grid to be the correct way looking, and rotate the hex to match the orientation.
Thank you for testing and helping me out, I ran a quick test to see all the places that aren’t correct, and to check if chunk_iy is correct indeed, it turns out that after testing the chunk_iy isn’t correct (the yellow lines)
This image is really handy, seeing both axes of the hexs and chunks. It also is showing why the code is failing. Since the code is the same as finding a hex by mouseclick (only slightly changed to match flat-hexagons instead of pointy-hexagons) so for finding chunks we are using the blue grid instead of the red grid so that’s wrong.
This also gives why the chunk_x isn’t accounting for hex_iy since the x-as of the blue grid is ‘‘straight’’.
And you are very right on this one, it has to do with trigonometry! That’s also why there is a Math.sqrt(3)/3 in the code.
The single pointy-hexagonals are a single hex and correct, the chunk is the group of colored hexes.
I’ve logged the input data and output data.
Everything after Adding Hexes to Chunk[chunk_ix , chunk_iy] belongs in that chunk so the hexes that are logged after that line need to have a minimal @-value of [chunk_ix - 0.5f, chunk_iy-0.5f] and a maximal @-value of [chunk_ix + 0.5f, chunk_iy + 0.5f] The yellow lines show output data that isn’t right
I will be adjusting the code to match the other grid.
Update:
I have been trying to create the grid, but before giving the codes it is needed you know what all the vars actually are.
So lets start with a single hexagon:
The values of these vars are based of their pixels/texel value.
And the values of the chunk variables are iteration values based on the number of hexagons
Because the vars are final the value of the var is given after the name (= …)
So I’ve been trying to translate the hex_ix and hex_iy from the hexagonal grid to a chunk_ix and chunk_iy value from the chunk grid. The following is what I’ve come up with, currently it’s more wrong than the previous code, but I believe this code is more correcter:Log-files