在Flash中绘制十六进制网格?

时间:2023-01-24 10:04:42

What's the easiest way to draw a hex grid algorithmically? How should I present them in data?

用算法绘制十六进制网格最简单的方法是什么?我应该如何在数据中显示它们?

For example, in a square grid, I could just save x-y coordinates..

例如,在一个方形网格中,我可以保存x-y坐标。

2 个解决方案

#1


7  

So hexagon is a neat library for AS3 games, it has some hexagon classes that might be handy in your research. This article has some very nice details about hexagon tiles in Flash.

六边形是一个简洁的AS3游戏库,它有一些六边形类可能对你的研究很有用。本文有一些关于Flash中六边形块的很好的细节。

#2


6  

There are several ways to manage hex map coordinates and most of them unintuitively insist on mapping them to x-y coordinates which is only important for rendering. Some form of polar coordinates is usually best. I have a perl library for managing most vector calculations which is very useful point-of-reference computing like AI and other search trees.

有几种方法可以管理十六进制映射坐标,其中大多数都不自觉地坚持将它们映射到x-y坐标,这对于渲染来说是非常重要的。某种形式的极坐标通常是最好的。我有一个perl库用于管理大多数向量计算,这是非常有用的参考点计算,如人工智能和其他搜索树。

http://en.wikipedia.org/wiki/Polar_coordinate_system

http://en.wikipedia.org/wiki/Polar_coordinate_system

For the cheap seats, polar coordinates plots a point as the origin (like the standard x-y Cartesian graph), picks a vector as a baseline (like the Cartesian) and then designates points as (magnitude, degrees).

对于便宜的座位,极坐标绘制一个点作为原点(如标准的x-y笛卡尔图),选择一个向量作为基线(如笛卡尔坐标),然后将点指定为(量值,度)。

Where this really hits a home-run with hex maps is that every pure angle is a multiple of 60 degrees. If you assign each hex side a facing ((a,b,d,e,f,g) and apply a vector as a magnitude and facing, several useful properties emerge.

这真的是一个本垒打与十六进制地图是每一个纯角是60度的倍数。如果你将每个hex面(a,b,d,e,f,g)分配,并将一个矢量应用于大小和面,就会出现几个有用的属性。

1) Every hex can be represented as a sum of two adjacent vectors (or a single vector where the second vector is a magnitude 0 or identity element). e.g. 1a+1b = 1a1b or 1b1a. Either way, it's a traversal of 2 hexes, a magnitude of 2, and designates a unique hex from the origin (0,0). 2) Non-adjacent vectors can always be simplified to two adjacent vectors applying these rules: 2) Negation: 1A + 1D = 0, 1B + 1E = 0, 1C + 1F = 0, e.g. 3) Combination : 1A + 1C = 1B, 1B + 1D = 1C, 1C + 1E = 1D, 1D + 1F = 1E, 1E + 1A = 1F

1)每个十六进制都可以表示为两个相邻向量的和(或一个单个向量,其中第二个向量为大小为0或单位元素)。例如1a+1b = 1a1b或1b1a。无论哪种方式,它都是2个6的遍历,大小为2,并从原点(0,0)指定一个唯一的十六进制。2)两向量总是可以简化为两个相邻向量应用这些规则:2)否定:1 + 1 d = 0,1 b + 1 e = 0,1 c + 1 f = 0,例如3)组合:1 + 1 c = 1 b,b + 1 d = 1 c,1 c + 1 e = 1 d,1 d + 1 f = 1 e,f 1 e + 1 = 1

Keeping these principles in mind, a missile that must traverse the actual space, needs to preserve the vectors as a concatenation or order of smaller traversals. 1A + 1A + 1C + 1C represents a missile that travels two hexes out and then banks sharply (120 degrees) and travels two hexes, ending its traversal only 2 hexes away but 60 degrees off course from it's initial direction.

记住这些原则,导弹必须穿越实际空间,需要将矢量保持为一个更小的串接或顺序。1A + 1A + 1C + 1C代表一种导弹,它从2个六边形中发射出去,然后快速地(120度)倾斜,然后再发射两个六边形,结束了它仅以2个六边形的距离,但离初始方向有60度的距离。

The targeting computer or resulting explosion, however, may only care about the range, so simplifying these vectors using those rules may be important. To figure out the shortest distance between any two points, simply concatenate the vectors and simplify them.

然而,目标计算机或产生的爆炸可能只关心范围,因此使用这些规则简化这些向量可能很重要。要求任意两点之间的最短距离,只需将向量串联起来并化简。

It's also pretty easy to create a hex map and render it Create a Hex Object as the origin with properties, Magnitude = 0, Vector = NULL, Label(optional) = some string (I like to make this the human readable value), Name = 0 (concatenation of the Magnitude and Vector), and Exits = Array (you'll populate 6 nodes, barring wormholes or other). Plot the Origin centered on the pixel you choose to make the center of the map. Render the hex. Choose a Radius for your map

也很容易创建一个十六进制地图和呈现它创建一个十六进制对象作为起源与性质,大小= 0,向量= NULL,标签(可选)=一些字符串(我喜欢这个人类可读的值),Name = 0(大小和向量的连接),并退出=数组(你会填充6节点,除非虫洞或其他)。绘制以你选择的使地图中心的像素为中心的原点。呈现十六进制。为地图选择一个半径

Foreach Magnitude, ---populate the ring with each combination of adjacent vectors. There are a number of ways to do this, but the simplest is choose a single vector as a base and then traverse Magnitude hexes in an appropriate direction and orbit with a 60 degree turn. e.g. For Magnitude 3, Start at 3E, then go 3A, 3B, 3C, 3D, 3E, 3F calculating each hex as sums of the last hex traversed and the new single hex vector. ---In each of these hexes, apply some trig to calculate where the center pixel should be relative to your origin pixel and render the hex

对于每个大小,---用每个相邻向量的组合填充环。有很多方法可以做到这一点,但是最简单的方法是选择一个单一的向量作为基,然后沿着一个合适的方向和轨道以60度的旋转。例如,对于3级,从3E开始,然后以3A、3B、3C、3D、3E、3F计算每个十六进制为最后一个十六进制和新的单十六进制向量的和。-- -- -- -- -- -- -- -- --运用一些三角函数来计算中心像素相对于原点像素的位置,并渲染十六进制

Hope that helps someone. Hex Maps rock. Rendering them sucks a bit.

希望可以帮助别人。十六进制地图岩石。让他们感觉有点糟。

#1


7  

So hexagon is a neat library for AS3 games, it has some hexagon classes that might be handy in your research. This article has some very nice details about hexagon tiles in Flash.

六边形是一个简洁的AS3游戏库,它有一些六边形类可能对你的研究很有用。本文有一些关于Flash中六边形块的很好的细节。

#2


6  

There are several ways to manage hex map coordinates and most of them unintuitively insist on mapping them to x-y coordinates which is only important for rendering. Some form of polar coordinates is usually best. I have a perl library for managing most vector calculations which is very useful point-of-reference computing like AI and other search trees.

有几种方法可以管理十六进制映射坐标,其中大多数都不自觉地坚持将它们映射到x-y坐标,这对于渲染来说是非常重要的。某种形式的极坐标通常是最好的。我有一个perl库用于管理大多数向量计算,这是非常有用的参考点计算,如人工智能和其他搜索树。

http://en.wikipedia.org/wiki/Polar_coordinate_system

http://en.wikipedia.org/wiki/Polar_coordinate_system

For the cheap seats, polar coordinates plots a point as the origin (like the standard x-y Cartesian graph), picks a vector as a baseline (like the Cartesian) and then designates points as (magnitude, degrees).

对于便宜的座位,极坐标绘制一个点作为原点(如标准的x-y笛卡尔图),选择一个向量作为基线(如笛卡尔坐标),然后将点指定为(量值,度)。

Where this really hits a home-run with hex maps is that every pure angle is a multiple of 60 degrees. If you assign each hex side a facing ((a,b,d,e,f,g) and apply a vector as a magnitude and facing, several useful properties emerge.

这真的是一个本垒打与十六进制地图是每一个纯角是60度的倍数。如果你将每个hex面(a,b,d,e,f,g)分配,并将一个矢量应用于大小和面,就会出现几个有用的属性。

1) Every hex can be represented as a sum of two adjacent vectors (or a single vector where the second vector is a magnitude 0 or identity element). e.g. 1a+1b = 1a1b or 1b1a. Either way, it's a traversal of 2 hexes, a magnitude of 2, and designates a unique hex from the origin (0,0). 2) Non-adjacent vectors can always be simplified to two adjacent vectors applying these rules: 2) Negation: 1A + 1D = 0, 1B + 1E = 0, 1C + 1F = 0, e.g. 3) Combination : 1A + 1C = 1B, 1B + 1D = 1C, 1C + 1E = 1D, 1D + 1F = 1E, 1E + 1A = 1F

1)每个十六进制都可以表示为两个相邻向量的和(或一个单个向量,其中第二个向量为大小为0或单位元素)。例如1a+1b = 1a1b或1b1a。无论哪种方式,它都是2个6的遍历,大小为2,并从原点(0,0)指定一个唯一的十六进制。2)两向量总是可以简化为两个相邻向量应用这些规则:2)否定:1 + 1 d = 0,1 b + 1 e = 0,1 c + 1 f = 0,例如3)组合:1 + 1 c = 1 b,b + 1 d = 1 c,1 c + 1 e = 1 d,1 d + 1 f = 1 e,f 1 e + 1 = 1

Keeping these principles in mind, a missile that must traverse the actual space, needs to preserve the vectors as a concatenation or order of smaller traversals. 1A + 1A + 1C + 1C represents a missile that travels two hexes out and then banks sharply (120 degrees) and travels two hexes, ending its traversal only 2 hexes away but 60 degrees off course from it's initial direction.

记住这些原则,导弹必须穿越实际空间,需要将矢量保持为一个更小的串接或顺序。1A + 1A + 1C + 1C代表一种导弹,它从2个六边形中发射出去,然后快速地(120度)倾斜,然后再发射两个六边形,结束了它仅以2个六边形的距离,但离初始方向有60度的距离。

The targeting computer or resulting explosion, however, may only care about the range, so simplifying these vectors using those rules may be important. To figure out the shortest distance between any two points, simply concatenate the vectors and simplify them.

然而,目标计算机或产生的爆炸可能只关心范围,因此使用这些规则简化这些向量可能很重要。要求任意两点之间的最短距离,只需将向量串联起来并化简。

It's also pretty easy to create a hex map and render it Create a Hex Object as the origin with properties, Magnitude = 0, Vector = NULL, Label(optional) = some string (I like to make this the human readable value), Name = 0 (concatenation of the Magnitude and Vector), and Exits = Array (you'll populate 6 nodes, barring wormholes or other). Plot the Origin centered on the pixel you choose to make the center of the map. Render the hex. Choose a Radius for your map

也很容易创建一个十六进制地图和呈现它创建一个十六进制对象作为起源与性质,大小= 0,向量= NULL,标签(可选)=一些字符串(我喜欢这个人类可读的值),Name = 0(大小和向量的连接),并退出=数组(你会填充6节点,除非虫洞或其他)。绘制以你选择的使地图中心的像素为中心的原点。呈现十六进制。为地图选择一个半径

Foreach Magnitude, ---populate the ring with each combination of adjacent vectors. There are a number of ways to do this, but the simplest is choose a single vector as a base and then traverse Magnitude hexes in an appropriate direction and orbit with a 60 degree turn. e.g. For Magnitude 3, Start at 3E, then go 3A, 3B, 3C, 3D, 3E, 3F calculating each hex as sums of the last hex traversed and the new single hex vector. ---In each of these hexes, apply some trig to calculate where the center pixel should be relative to your origin pixel and render the hex

对于每个大小,---用每个相邻向量的组合填充环。有很多方法可以做到这一点,但是最简单的方法是选择一个单一的向量作为基,然后沿着一个合适的方向和轨道以60度的旋转。例如,对于3级,从3E开始,然后以3A、3B、3C、3D、3E、3F计算每个十六进制为最后一个十六进制和新的单十六进制向量的和。-- -- -- -- -- -- -- -- --运用一些三角函数来计算中心像素相对于原点像素的位置,并渲染十六进制

Hope that helps someone. Hex Maps rock. Rendering them sucks a bit.

希望可以帮助别人。十六进制地图岩石。让他们感觉有点糟。