欢迎阅读指正和转载,但请尊重原作者的工作,转载时请务必注明转载自:www.xionggf.com
 
战棋游戏的六边形格子(翻译)
 
 
其他参考文档
 
兵棋学院】兵棋中为何使用六角格(正六边形)?
doc文件下载
战棋游戏的蜂巢型地图与菱形地图在游戏设计来说有何优劣?
知乎上的提问和回答
为什么战棋游戏的地图网格大多采用六边形设计?
知乎上的提问和回答
 
Hexagonal grids are used in some games but aren’t quite as straightforward or common as square grids. I’ve been collecting hex grid resources for nearly 20 years, and wrote this guide to the most elegant approaches that lead to the simplest code, largely based on the guides by Charles Fu and Clark Verbrugge. I’ll describe the various ways to make hex grids, the relationships between them, as well as some common algorithms. Many parts of this page are interactive; choosing a type of grid will update diagrams, code, and text to match. 在一些游戏中使用了六边形地图格。但是六边形地图格不像正方形格子那么直观和常用。我收集六边形地图格的相关资料已经将近二十年。我用最简单的代码,以最简练的方式去撰写了这篇指南教程。这篇教程参考了Charles FuClark Verbrugge的教程。我将会在本文中描述多种创建六边形地图格的方法;这些方法之间的关系,以及一些通用的算法。本页面中的很多部分都是可交互的。选择不同类型的格子,将会对应更新流程图,代码和文本。
 
The code samples on this page are written in pseudo-code; they’re meant to be easy to read and understand so that you can write your own implementation. 本文中的代码是伪代码。这将意味着这些代码是便于阅读和理解的。你可以用你自己的编程语言去根据这些伪代码实现它。
 
Geometry
 
Hexagons are 6-sided polygons. Regular hexagons have all the sides (edges) the same length. I’ll assume all the hexagons we’re working with here are regular. The typical orientations for hex grids are horizontal (pointy topped) and vertical (flat topped). 所谓的六边形就是指六条边的多边形。正六边形是指它的所有的边的长度都是相等的。在本文中讨论的所有六边形都约定为正六边形。六边形的两个最典型的朝向就是水平朝向(pointy topped)和垂直朝向(pointy topped)。
 
 
Horizontal (pointy topped )
Vertical(flat topped)
 
 
 
 
Hexagons have 6 edges. Each edge is shared by 2 hexagons. Hexagons have 6 corners. Each corner is shared by 3 hexagons. For more about centers, edges, and corners, see my article on grid parts (squares, hexagons, and triangles). 六边形有6条边,每条边为两个相邻的六边形所共有。六边形有6个角,每个角由3个六边形所共享。要了解更多的关于多边形的角,终点,边。请参考我的这篇文章
 
Angle
 
In a regular hexagon the interior angles are 120°. There are six “wedges”, each an equilateral triangle with 60° angles inside. Corner i is at (60° * i) + 30°, size units away from the center. In code: 对于pointy topped朝向的六边形而言,正六边形的每一个内角的度数是120度。正六边形可视为由6个楔方(wedge)。即6个等边三角形拼成。每个等边三角形的内角为60度。六边形的每一个顶点与六边形中点的连线,与水平轴的夹角的值,以顺时针为正向的话。这个角的大小计算公式为(60° * i) + 30°。伪代码如下:
 
-- center是指六边形中点坐标,size是指六边形的边长,i为顶点编号值
function hex_corner(center, size, i):
      var angle_deg = 60 * i + 30 -- 角度
      var angle_rad = PI / 180 * angle_deg -- 弧度,弧度 = 圆周率除以180再乘以角度
       return Point(center.x + size * cos(angle_rad),
          center.y + size * sin(angle_rad))
 
In a regular hexagon the interior angles are 120°. There are six “wedges”, each an equilateral triangle with 60° angles inside. Corner i is at (60° * i), size units away from the center. In code: 对于flat topped朝向的六边形而言,正六边形的每一个内角的度数是120度。正六边形可视为由6个楔方(wedge)。即6个等边三角形拼成。每个等边三角形的内角为60度。六边形的每一个顶点与六边形中点的连线,与水平轴的夹角的值,以顺时针为正向的话。这个角的大小计算公式为(60° * i)。伪代码如下:
 
-- center是指六边形中点坐标,size是指六边形的边长,i为顶点编号值
function hex_corner(center, size, i):
      var angle_deg = 60 * i -- 角度
      var angle_rad = PI / 180 * angle_deg -- 弧度,弧度 = 圆周率除以180再乘以角度
       return Point(center.x + size * cos(angle_rad),
          center.y + size * sin(angle_rad))