hexagonal-tiles

Mathematically producing sphere-shaped hexagonal grid

扶醉桌前 提交于 2019-11-30 13:28:29
问题 I am trying to create a shape similar to this, hexagons with 12 pentagons, at an arbitrary size. (Image Source) The only thing is, I have absolutely no idea what kind of code would be needed to generate it! The goal is to be able to take a point in 3D space and convert it to a position coordinate on the grid, or vice versa and take a grid position and get the relevant vertices for drawing the mesh. I don't even know how one would store the grid positions for this. Does each "triagle section"

Hexagonal tiles and finding their adjacent neighbours

孤街浪徒 提交于 2019-11-30 12:25:24
问题 I'm developing a simple 2D board game using hexagonal tile maps, I've read several articles (including the gamedev one's, which are linked every time there's a question on hexagonal tiles) on how to draw hexes on the screen and how to manage the movement (though much of it I had already done before). My main problem is finding the adjacent tiles based on a given radius. This is how my map system works: (0,0) (0,1) (0,2) (0,3) (0,4) (1,0) (1,1) (1,2) (1,3) (1,4) (2,0) (2,1) (2,2) (2,3) (2,4)

ggplot2 multiple stat_binhex() plots with different color gradients in one image

做~自己de王妃 提交于 2019-11-30 06:56:10
I'd like to use ggplot2's stat_binhex() to simultaneously plot two independent variables on the same chart, each with its own color gradient using scale_colour_gradientn(). If we disregard the fact that the x-axis units do not match, a reproducible example would be to plot the following in the same image while maintaining separate fill gradients. d <- ggplot(diamonds, aes(x=carat,y=price))+ stat_binhex(colour="white",na.rm=TRUE)+ scale_fill_gradientn(colours=c("white","blue"),name = "Frequency",na.value=NA) try(ggsave(plot=d,filename=<some file>,height=6,width=8)) d <- ggplot(diamonds, aes(x

Hexagonal tiles and finding their adjacent neighbours

左心房为你撑大大i 提交于 2019-11-30 02:04:48
I'm developing a simple 2D board game using hexagonal tile maps, I've read several articles (including the gamedev one's, which are linked every time there's a question on hexagonal tiles) on how to draw hexes on the screen and how to manage the movement (though much of it I had already done before). My main problem is finding the adjacent tiles based on a given radius. This is how my map system works: (0,0) (0,1) (0,2) (0,3) (0,4) (1,0) (1,1) (1,2) (1,3) (1,4) (2,0) (2,1) (2,2) (2,3) (2,4) (3,0) (3,1) (3,2) (3,3) (3,4) etc... What I'm struggling with is the fact that I cant just 'select' the

Manhattan Distance between tiles in a hexagonal grid

梦想的初衷 提交于 2019-11-28 05:26:34
For a square grid the euclidean distance between tile A and B is: distance = sqrt(sqr(x1-x2)) + sqr(y1-y2)) For an actor constrained to move along a square grid, the Manhattan Distance is a better measure of actual distance we must travel: manhattanDistance = abs(x1-x2) + abs(y1-y2)) How do I get the manhattan distance between two tiles in a hexagonal grid as illustrated with the red and blue lines below? aaz I once set up a hexagonal coordinate system in a game so that the y -axis was at a 60-degree angle to the x -axis. This avoids the odd-even row distinction. (source: althenia.net ) The

Hexagonal Grids, how do you find which hexagon a point is in?

懵懂的女人 提交于 2019-11-28 03:34:53
I have a map made up of rows and columns of hexagons This isn't an actual image of the hex-map I am using, but uses the same size and shape hexagons I need to be able to tell which one the mouse is over when the user clicks, Each Hexagon is represented by an instance of a "Tile" class, however this doesn't hold any location specific data, or even a polygon, so basically the only way to tell where a particular hexagon is, is to know it's position in the 2D array. I have used a square grid before, and it was relatively easy to figure out which square was selected, because pixels are also square,

Algorithm to generate a hexagonal grid with coordinate system

南楼画角 提交于 2019-11-27 18:12:42
I am trying to roll up 19 lines of code into a single for loop, but I am feeling a bit stumped. The reason I ask, is because I want the grid to be other sizes instead of 5. In Main::drawHexGridAdvanced() , I am trying to deduce the similarities between each line as opposed to Main::drawHexGridBasic() where I am hard-coding values. I am not sure how to determine the start of the x for each column in each row, because the pattern for n == 5 is 0, -1 -2 -2 -2 after that each consecutive column is just incremented except when the loop reaches the halfway point... Information and Understanding `n`

Generating triangular/hexagonal coordinates (xyz)

家住魔仙堡 提交于 2019-11-27 17:21:10
I'm trying to come up with an iterative function that generates xyz coordinates for a hexagonal grid. With a starting hex position (say 0,0,0 for simplicity), I want to calculate the coordinates for each successive "ring" of hexagons, as illustrated here: So far, all I've managed to come up with is this (example in javascript): var radius = 3 var xyz = [0,0,0]; // for each ring for (var i = 0; i < radius; i++) { var tpRing = i*6; var tpVect = tpRing/3; // for each vector of ring for (var j = 0; j < 3; j++) { // for each tile in vector for(var k = 0; k < tpVect; k++) { xyz[0] = ???; xyz[1] = ??

Setting hex bins in ggplot2 to same size

半世苍凉 提交于 2019-11-27 16:01:03
问题 I'm trying to make a hexbin representation of data in several categories. The problem is, facetting these bins seems to make all of them different sizes. set.seed(1) #Create data bindata <- data.frame(x=rnorm(100), y=rnorm(100)) fac_probs <- dnorm(seq(-3, 3, length.out=26)) fac_probs <- fac_probs/sum(fac_probs) bindata$factor <- sample(letters, 100, replace=TRUE, prob=fac_probs) library(ggplot2) #Actual plotting library(hexbin) ggplot(bindata, aes(x=x, y=y)) + geom_hex() + facet_wrap(~factor)

Hexagonal Grids, how do you find which hexagon a point is in?

时光总嘲笑我的痴心妄想 提交于 2019-11-27 00:03:50
问题 I have a map made up of rows and columns of hexagons This isn't an actual image of the hex-map I am using, but uses the same size and shape hexagons I need to be able to tell which one the mouse is over when the user clicks, Each Hexagon is represented by an instance of a "Tile" class, however this doesn't hold any location specific data, or even a polygon, so basically the only way to tell where a particular hexagon is, is to know it's position in the 2D array. I have used a square grid