Spanish Fly for two - how they affect libido in women and men
Contents Biologically active additive based on an extract obtained from a beetle with a fly (or fly...
The topic of polygons is covered in the school curriculum, but they do not pay enough attention to it. Meanwhile, it is interesting, and this is especially true of a regular hexagon or hexagon - after all, many natural objects have this shape. These include honeycombs and more. This form is very well applied in practice.
A regular hexagon is a plane figure that has six sides equal in length and the same number of equal angles.
If we recall the formula for the sum of the angles of a polygon
it turns out that in this figure it is equal to 720 °. Well, since all the angles of the figure are equal, it is easy to calculate that each of them is equal to 120 °.
Drawing a hexagon is very simple, all you need is a compass and a ruler.
The step by step instructions will look like this:
If desired, you can do without a line by drawing five circles of equal radius.
The figure thus obtained will be a regular hexagon, and this can be proved below.
To understand the properties of a regular hexagon, it makes sense to break it into six triangles:
This will help in the future to more clearly display its properties, the main of which are:
It is possible to describe a circle around a hexagon, and moreover, only one. Since this figure is correct, you can do it quite simply: draw a bisector from two adjacent angles inside. They intersect at point O, and together with the side between them form a triangle.
The angles between the side of the hexagon and the bisectors will be 60° each, so we can definitely say that a triangle, for example, AOB, is isosceles. And since the third angle will also be equal to 60 °, it is also equilateral. It follows that the segments OA and OB are equal, which means that they can serve as the radius of the circle.
After that, you can go to the next side, and also draw a bisector from the angle at point C. It will turn out another equilateral triangle, and side AB will be common to two at once, and OS will be the next radius through which the same circle goes. There will be six such triangles in total, and they will have a common vertex at point O. It turns out that it will be possible to describe the circle, and it is only one, and its radius is equal to the side of the hexagon:
That is why it is possible to construct this figure with the help of a compass and a ruler.
Well, the area of \u200b\u200bthis circle will be standard:
The center of the circumscribed circle coincides with the center of the inscribed one. To verify this, we can draw perpendiculars from the point O to the sides of the hexagon. They will be the heights of those triangles that make up the hexagon. And in an isosceles triangle, the height is the median with respect to the side on which it rests. Thus, this height is nothing but the perpendicular bisector, which is the radius of the inscribed circle.
The height of an equilateral triangle is calculated simply:
h²=a²-(a/2)²= a²3/4, h=a(√3)/2
And since R=a and r=h, it turns out that
r=R(√3)/2.
Thus, the inscribed circle passes through the centers of the sides of a regular hexagon.
Its area will be:
S=3πa²/4,
that is, three-quarters of that described.
Everything is clear with the perimeter, this is the sum of the lengths of the sides:
P=6a, or P=6R
But the area will be equal to the sum of all six triangles into which the hexagon can be divided. Since the area of a triangle is calculated as half the product of the base and the height, then:
S \u003d 6 (a / 2) (a (√3) / 2) \u003d 6a² (√3) / 4 \u003d 3a² (√3) / 2 or
S=3R²(√3)/2
Those who wish to calculate this area through the radius of the inscribed circle can be done like this:
S=3(2r/√3)²(√3)/2=r²(2√3)
A triangle can be inscribed in a hexagon, the sides of which will connect the vertices through one:
There will be two of them in total, and their imposition on each other will give the Star of David. Each of these triangles is equilateral. This is easy to verify. If you look at the AC side, then it belongs to two triangles at once - BAC and AEC. If in the first of them AB \u003d BC, and the angle between them is 120 °, then each of the remaining ones will be 30 °. From this we can draw logical conclusions:
Intersecting with each other, the triangles form a new hexagon, and it is also regular. It's easy to prove:
Thus, the figure meets the signs of a regular hexagon - it has six equal sides and angles. From the equality of triangles at the vertices, it is easy to deduce the length of the side of the new hexagon:
d=а(√3)/3
It will also be the radius of the circle described around it. The radius of the inscribed will be half the side of the large hexagon, which was proved when considering the triangle ABC. Its height is exactly half of the side, therefore, the second half is the radius of the circle inscribed in the small hexagon:
r₂=а/2
S=(3(√3)/2)(а(√3)/3)²=а(√3)/2
It turns out that the area of the hexagon inside the star of David is three times smaller than that of the large one in which the star is inscribed.
The properties of the hexagon are very actively used both in nature and in various fields of human activity. First of all, this applies to bolts and nuts - the hats of the first and second are nothing more than a regular hexagon, if you do not take into account the chamfers. The size of wrenches corresponds to the diameter of the inscribed circle - that is, the distance between opposite faces.
Has found its application and hexagonal tiles. It is much less common than a quadrangular one, but it is more convenient to lay it: three tiles meet at one point, not four. Compositions can be very interesting:
Concrete paving slabs are also produced.
The prevalence of the hexagon in nature is explained simply. Thus, it is easiest to fit circles and balls tightly on a plane if they have the same diameter. Because of this, honeycombs have such a shape.
Construction of a regular hexagon inscribed in a circle. Construction of a regular pentagon given its side. Move the compass needle to the intersection point of the just drawn arc with the circle. This construction can be done using a square and a compass. A regular hexagon can be constructed using a T-square and a 30X60° square. Construct the vertex points of the corners of a regular hexagon.
Construction of an equilateral triangle inscribed in a circle. The vertices of such a triangle can be constructed using a compass and a square with angles of 30 and 60 °, or only one compass. To build side 2-3, set the T-square to the position shown by the dashed lines, and draw a straight line through point 2, which will define the third vertex of the triangle.
We mark point 1 on the circle and take it as one of the vertices of the pentagon. Let a circle of diameter D be given; you need to inscribe a regular heptagon into it (Fig. 65). Divide the vertical diameter of the circle into seven equal parts. From point 7 with a radius equal to the diameter of the circle D, we describe the arc until it intersects with the continuation of the horizontal diameter at point F. Point F is called the pole of the polygon.
The first column of this table contains the number of sides of a regular inscribed polygon, and the second column contains the coefficients. The length of a side of a given polygon is obtained by multiplying the radius of a given circle by a factor corresponding to the number of sides of this polygon.
The topic of this video tutorial is "Constructing Regular Polygons". We will also once again give the definition of a regular polygon, depict it graphically, after which we will once again make sure that the centers of the inscribed and circumscribed circles around such a figure will coincide. A circle can always be inscribed in this polygon, and a circle can always be circumscribed around it. In the course of previous lessons, we found out that the basic role for describing the properties of polygons is played by the bisectors of its angles and the perpendicular bisectors to its sides.
4. We got the desired regular triangle ABC. Problem solved. 3. Having placed one leg of the compass at an arbitrary point A1 on the circle, with the help of the second leg we mark point A2 on the same circle and connect it with point A1. We get the first side of the hexagon. 3. Using the perpendicular bisectors to the sides of the polygon, lowered from the point O, we divide all its sides and all the arcs of the circle enclosed between its adjacent vertices in half.
Geometric constructions are one of the important parts of learning. The needle should pierce the drawn line. The more accurately the compass is set, the more accurate the construction will be. Draw another arc that intersects the circle. Consistently connect all six points of intersection of the arcs with the originally drawn circle. In this case, the hexagon may turn out to be wrong.
We connect the found vertices in series with each other. The heptagon can be constructed by drawing rays from the F pole and through odd divisions of the vertical diameter. The centers of both circles coincide (point O in Fig. 1). The figure also shows the radii of the circumscribed (R) and inscribed (r) circles.
The construction of a hexagon is based on the fact that its side is equal to the radius of the circumscribed circle. In this lesson, we will look at ways to construct regular polygons using a compass and ruler. The second method is based on the fact that if you build a regular hexagon inscribed in a circle, and then connect its vertices through one, you get an equilateral triangle. The above method is suitable for constructing regular polygons with any number of sides.
Construction of a regular hexagon inscribed in a circle. The construction of a hexagon is based on the fact that its side is equal to the radius of the circumscribed circle. Therefore, to build, it is enough to divide the circle into six equal parts and connect the found points to each other (Fig. 60, a).
A regular hexagon can be constructed using a T-square and a 30X60° square. To perform this construction, we take the horizontal diameter of the circle as the bisector of angles 1 and 4 (Fig. 60, b), build sides 1-6, 4-3, 4-5 and 7-2, after which we draw sides 5-6 and 3- 2.
Construction of an equilateral triangle inscribed in a circle. The vertices of such a triangle can be constructed using a compass and a square with angles of 30 and 60 °, or only one compass.
Consider two ways to construct an equilateral triangle inscribed in a circle.
First way(Fig. 61, a) is based on the fact that all three angles of the triangle 7, 2, 3 each contain 60 °, and the vertical line drawn through the point 7 is both the height and the bisector of angle 1. Since the angle 0-1- 2 is equal to 30°, then to find the side
1-2, it is enough to build an angle of 30 ° at point 1 and side 0-1. To do this, set the T-square and square as shown in the figure, draw a line 1-2, which will be one of the sides of the desired triangle. To build side 2-3, set the T-square to the position shown by the dashed lines, and draw a straight line through point 2, which will define the third vertex of the triangle.
Second way is based on the fact that if you build a regular hexagon inscribed in a circle, and then connect its vertices through one, you get an equilateral triangle.
To build a triangle (Fig. 61, b), we mark a vertex-point 1 on the diameter and draw a diametrical line 1-4. Further, from point 4 with a radius equal to D / 2, we describe the arc until it intersects with the circle at points 3 and 2. The resulting points will be two other vertices of the desired triangle.
Construction of a square inscribed in a circle. This construction can be done using a square and a compass.
The first method is based on the fact that the diagonals of the square intersect in the center of the circumscribed circle and are inclined to its axes at an angle of 45°. Based on this, we install a T-square and a square with angles of 45 ° as shown in Fig. 62, a, and mark points 1 and 3. Further, through these points, we draw the horizontal sides of the square 4-1 and 3-2 with the help of a T-square. Then, using a T-square along the leg of the square, we draw the vertical sides of the square 1-2 and 4-3.
The second method is based on the fact that the vertices of the square bisect the arcs of the circle enclosed between the ends of the diameter (Fig. 62, b). We mark points A, B and C at the ends of two mutually perpendicular diameters, and from them with a radius y we describe the arcs until they intersect.
Further, through the points of intersection of the arcs, we draw auxiliary lines, marked on the figure with solid lines. Their points of intersection with the circle will define vertices 1 and 3; 4 and 2. The vertices of the desired square obtained in this way are connected in series with each other.
Construction of a regular pentagon inscribed in a circle.
To inscribe a regular pentagon in a circle (Fig. 63), we make the following constructions.
We mark point 1 on the circle and take it as one of the vertices of the pentagon. Divide segment AO in half. To do this, with the radius AO from point A, we describe the arc to the intersection with the circle at points M and B. Connecting these points with a straight line, we get the point K, which we then connect to point 1. With a radius equal to the segment A7, we describe the arc from point K to the intersection with the diametrical line AO at point H. Connecting point 1 with point H, we get the side of the pentagon. Then, with a compass opening equal to the segment 1H, describing the arc from vertex 1 to the intersection with the circle, we find vertices 2 and 5. Having made notches from vertices 2 and 5 with the same compass opening, we obtain the remaining vertices 3 and 4. We connect the found points sequentially with each other.
Construction of a regular pentagon given its side.
To construct a regular pentagon along its given side (Fig. 64), we divide the segment AB into six equal parts. From points A and B with radius AB we describe arcs, the intersection of which will give point K. Through this point and division 3 on the line AB we draw a vertical line.
We get the point 1-vertex of the pentagon. Then, with a radius equal to AB, from point 1 we describe the arc to the intersection with the arcs previously drawn from points A and B. The intersection points of the arcs determine the vertices of the pentagon 2 and 5. We connect the found vertices in series with each other.
Construction of a regular heptagon inscribed in a circle.
Let a circle of diameter D be given; you need to inscribe a regular heptagon into it (Fig. 65). Divide the vertical diameter of the circle into seven equal parts. From point 7 with a radius equal to the diameter of the circle D, we describe the arc until it intersects with the continuation of the horizontal diameter at point F. Point F is called the pole of the polygon. Taking point VII as one of the vertices of the heptagon, we draw rays from the pole F through even divisions of the vertical diameter, the intersection of which with the circle will determine the vertices VI, V and IV of the heptagon. To obtain vertices / - // - /// from points IV, V and VI, we draw horizontal lines until they intersect with the circle. We connect the found vertices in series with each other. The heptagon can be constructed by drawing rays from the F pole and through odd divisions of the vertical diameter.
The above method is suitable for constructing regular polygons with any number of sides.
The division of a circle into any number of equal parts can also be done using the data in Table. 2, which shows the coefficients that make it possible to determine the dimensions of the sides of regular inscribed polygons.
Geometric constructions are one of the main parts of learning. They form spatial and logical thinking, and also allow you to understand the primitive and natural geometric validity. Constructions are made on a plane using a compass and a ruler. These tools allow you to build a large number of geometric shapes. At the same time, many figures that seem rather difficult are built using the simplest rules. Let's say, how to build a true hexagon, it is allowed to describe each in a few words.
You will need
1. Draw a circle. Set some distance between the legs of the compass. This distance will be the radius of the circle. Choose a radius in such a way that drawing a circle is quite comfortable. The circle must fit entirely on the sheet of paper. Too large or too small a distance between the legs of the compass can lead to its change during drawing. The optimal distance will be at which the angle between the legs of the compass is 15-30 degrees.
2. Construct the vertex points of the corners of a regular hexagon. Set the leg of the compass, in which the needle is fixed, to any point on the circle. The needle should pierce the drawn line. The more correct the compass is set, the more correct the construction will be. Draw an arc of a circle so that it intersects the previously drawn circle. Move the compass needle to the intersection point of the just drawn arc with the circle. Draw another arc that intersects the circle. Move the compass needle again to the intersection point of the arc and the circle and draw the arc again. Repeat this action three more times, moving in the same direction around the circle. Each should get six arcs and six intersection points.
3. Construct a positive hexagon. Stepwise combine all six points of intersection of the arcs with the originally drawn circle. Connect the dots with straight lines drawn with a ruler and pencil. After the actions performed, a true hexagon inscribed in a circle will be obtained.
hexagon A polygon is considered to have six angles and six sides. Polygons are both convex and concave. In a convex hexagon, all internal angles are obtuse; in a concave one or more angles are acute. The hexagon is fairly easy to construct. This is done in a couple of steps.
You will need
1. A sheet of paper is taken and 6 points are marked on it approximately as shown in Fig. 1.
2. Later, after the points were marked, a ruler, a pencil are taken and with their help stepwise, one after another, the points are connected as it looks in Fig. 2.
Related videos
Note!
The sum of all interior angles of a hexagon is 720 degrees.
Hexagon is a polygon, one that has six corners. In order to draw an arbitrary hexagon, you need to do each 2 steps.
You will need
1. You need to take a pencil in your hand and mark 6 arbitrary points on the sheet. In the future, these points will play the role of corners in the hexagon. (fig.1)
2. Take a ruler and draw 6 segments at these points, which would be connected to each other at the previously drawn points (Fig. 2)
Related videos
Note!
A special type of hexagon is the positive hexagon. It is called such because all its sides and angles are equal to each other. It is possible to describe or inscribe a circle around such a hexagon. It is worth noting that at the points that are obtained by touching the inscribed circle and the sides of the hexagon, the sides of the positive hexagon are divided in half.
Helpful advice
In nature, positive hexagons are very popular. For example, the entire honeycomb has a positive hexagonal shape. Or the crystal lattice of graphene (modification of carbon) also has the shape of a positive hexagon.
How to raise one or the other corner is a big question. But for some angles, the task is invisibly simplified. One of these angles is corner at 30 degrees. It is equal to? / 6, that is, the number 30 is a divisor of 180. Plus, its sine is known. This helps in its construction.
You will need
1. To begin with, consider a particularly primitive setting when you have a protractor in your hands. Then a straight line at an angle of 30 degrees to this one can be easily postponed with support for it.
2. In addition to the protractor, there are corner corners, one of the angles of which is equal to 30 degrees. Then another corner corner the angle will be equal to 60 degrees, that is, you need a visually smaller corner to construct the required line.
3. Now let's move on to non-trivial ways to construct an angle of 30 degrees. As you know, the sine of an angle of 30 degrees is 1/2. To build it, we need to build straight corner th tri corner nik. Perhaps we can build two perpendicular lines. But the tangent of 30 degrees is an irrational number, so we can only calculate the ratio between the legs approximately (only if there is no calculator), and, therefore, build corner about 30 degrees.
4. In this case, it is also possible to make an exact construction. We will again raise two perpendicular lines, on which the legs will be located directly corner tre corner nika. Let us set aside one straight leg BC of some length with the support of a compass (B is a straight corner). After that, we will increase the length between the legs of the compass by 2 times, which is elementary. Drawing a circle centered at point C with a radius of this length, we find the point of intersection of the circle with another straight line. This point will be point A straight corner tre corner ABC, and corner A will be equal to 30 degrees.
5. Erect corner in 30 degrees is allowed and with the support of the circle, applying what it is equal to?/6. Let's build a circle with radius OB. Let us consider in the theory of corner circle, where OA = OB = R is the radius of the circle, where corner OAB = 30 degrees. Let OE be the height of this isosceles triangle corner nika, and, consequently, its bisector and median. Then corner AOE = 15 degrees, and by the half angle formula, sin(15o) = (sqrt(3)-1)/(2*sqrt(2)). Therefore, AE = R*sin(15o). Otsel, AB = 2AE = 2R*sin(15o). Building a circle with radius BA centered at point B, we find the intersection point A of this circle with the initial one. Angle AOB will be 30 degrees.
6. If we can determine the length of the arcs in some way, then, setting aside the arc of length ?*R/6, we also get corner at 30 degrees.
Note!
It must be remembered that in paragraph 5 we can only approximate an angle, because irrational numbers will appear in the calculations.
hexagon called a special case of a polygon - a figure formed by the majority of points in a plane bounded by a closed polyline. A positive hexagon (hexagon), in turn, is also a special case - it is a polygon with six equal sides and equal angles. This figure is significant in that the length of all of its sides is equal to the radius of the circle described around the figure.
You will need
1. Select the length of the side of the hexagon. Take a compass and set the distance between the end of the needle, located on one of its legs, and the end of the stylus, located on the other leg, equal to the length of the side of the figure being drawn. To do this, you can use a ruler or prefer a random distance if this moment is not significant. Fix the legs of the compass with a screw, if possible.
2. Draw a circle with a compass. The selected distance between the legs will be the radius of the circle.
3. Divide the circle with dots into six equal parts. These points will be the vertices of the corners of the hexagon and, accordingly, the ends of the segments representing its sides.
4. Set the leg of the compass with the needle to an arbitrary point located on the line of the outlined circle. The needle should correctly pierce the line. The accuracy of the constructions directly depends on the accuracy of the installation of the compass. Draw an arc with a compass so that it intersects at 2 points the circle drawn first.
5. Move the leg of the compass with the needle to one of the intersection points of the drawn arc with the original circle. Draw another arc that also intersects the circle at 2 points (one of them will coincide with the point of the previous location of the compass needle).
6. In the same way, rearrange the compass needle and draw arcs four more times. Move the leg of the compass with the needle in one direction around the circumference (invariably clockwise or counterclockwise). As a result, six points of intersection of the arcs with the initially constructed circle must be identified.
7. Draw a positive hexagon. Stepwise pairwise combine the six points obtained in the previous step with segments. Draw line segments with a pencil and ruler. The result will be a true hexagon. Later, the implementation of the construction is allowed to erase the auxiliary elements (arcs and circles).
Note!
It makes sense to choose such a distance between the legs of the compass, so that the angle between them is equal to 15-30 degrees, on the contrary, when building constructions, this distance can easily go astray.
When building or developing home design plans, it is often necessary to build corner, equal to the existing one. Samples and school geometry skills come to support.
1. An angle is formed by two straight lines emanating from the same point. This point will be called the vertex of the corner, and the lines will be the sides of the corner.
2. Use three letters to designate corners: one at the top, two at the sides. are called corner, starting with the letter that stands on one side, then they call the letter standing at the top, and after that the letter on the other side. Use other methods to mark corners if you are more comfortable opposite. Occasionally, only one letter is called, which is at the top. And it is allowed to designate angles with Greek letters, say, α, β, γ.
3. There are situations when you need to draw corner so that it is equal to the given angle. If there is no probability to use a protractor when constructing a drawing, it is allowed to do only with a ruler and a compass. Possible, on the straight line indicated in the drawing by the letters MN, it is necessary to build corner at point K, so that it is equal to angle B. That is, from point K you need to draw a straight line forming with the line MN corner, the one that will be equal to the angle B.
4. First, mark a point on the entire side of this corner, say, points A and C, then unite points C and A with a straight line. Get tre corner nik ABC.
5. Now construct on the line MN the same three corner so that its vertex B is on the line at point K. Use the rule for constructing a triangle corner nika on three sides. Set aside the segment KL from point K. It must be equal to the segment BC. Get point L.
6. From point K, draw a circle with a radius equal to the segment BA. From L draw a circle with radius CA. Combine the resulting point (P) of the intersection of 2 circles with K. Get a tri corner nick KPL, the one that will be equal to tre corner niku ABC. So you get corner K. It will be equal to angle B. In order to make this construction more comfortable and faster, set aside equal segments from vertex B, using one compass solution, without moving the legs, describe the circle with the same radius from point K.
Related videos
Note!
Avoid accidental metamorphosis of the distance between the legs of the compass. In this case, the hexagon may turn out to be wrong.
Helpful advice
It makes sense to make constructions with the help of a compass with a perfectly sharpened stylus. So the constructions will be especially accurate.
Grids of hexagons (hexagonal grids) are used in some games, but they are not as simple and common as grids of rectangles. I've been collecting resources about hex grids for almost 20 years now, and I've written this guide to the most elegant approaches implemented in the simplest code. The article makes frequent use of the manuals of Charles Fu and Clark Verbrugge. I will describe the different ways to create hexagon grids, their relationship, as well as the most common algorithms. Many parts of this article are interactive: selecting a grid type changes the corresponding diagrams, code, and texts. (Note per .: this only applies to the original, I advise you to study it. In the translation, all the information of the original is preserved, but without interactivity.).
The code examples in the article are written in pseudocode, so they are easier to read and understand in order to write your own implementation.
Flat (left) and sharp (right) topped hexagons
Hexagons have 6 faces. Each face is shared by two hexagons. Hexagons have 6 corner points. Each corner point is shared by three hexagons. You can read more about centers, edges, and corner points in my article on mesh parts (squares, hexagons, and triangles).
Function hex_corner(center, size, i): var angle_deg = 60 * i + 30 var angle_rad = PI / 180 * angle_deg return Point(center.x + size * cos(angle_rad), center.y + size * sin(angle_rad) )
To fill a hexagon, you need to get the vertices of the polygon from hex_corner(…, 0) to hex_corner(…, 5) . To draw the outline of the hexagon, you need to use these vertices, and then draw the line again in hex_corner(…, 0) .
The difference between the two orientations is that x and y are swapped, which causes the angles to change: flat top hexagons have angles of 0°, 60°, 120°, 180°, 240°, 300°, and sharp top hexagons have 30 °, 90°, 150°, 210°, 270°, 330°.
Hexagon corners with flat and sharp top
The width of the hexagon is width = sqrt(3)/2 * height . Horizontal distance between adjacent hexagons horiz = width .
Some games use pixel art for the hexagons, which does not exactly match the correct hexagons. The angle and position formulas described in this section will not match the dimensions of such hexagons. The rest of the article describing the hexagon grid algorithms applies even if the hexagons are slightly stretched or compressed.
Horizontal arrangement "odd-r"
Horizontal arrangement "even-r"
Vertical arrangement "odd-q"
Vertical arrangement "even-q"
Take a grid of cubes and cut out diagonal plane at x + y + z = 0 . This is a strange idea, but it will help us simplify the hexagon grid algorithms. In particular, we will be able to use standard operations from Cartesian coordinates: summing and subtracting coordinates, multiplying and dividing by a scalar value, and also distances.
Notice the three main axes on the grid of cubes and their relationship to the six diagonal directions of the grid of hexagons. The diagonal axes of the grid correspond to the main direction of the grid of hexagons.
Since we already have algorithms for grids of squares and cubes, using cubic coordinates allows us to adapt these algorithms to grids of hexagons. I will be using this system for most of the article's algorithms. To use algorithms with a different coordinate system, I will transform the cubic coordinates, run the algorithm, and then transform them back.
Learn how cubic coordinates work for a grid of hexagons. When selecting hexagons, cubic coordinates corresponding to the three axes are highlighted.
There are many different coordinate systems for cubes and hexagons. In some of them, the condition differs from x + y + z = 0 . I showed only one of the many systems. You can also create cubic coordinates with x-y , y-z , z-x , which will have their own set of interesting properties, but I won't cover them here.
But you might argue that you don't want to store 3 numbers for coordinates because you don't know how to store a map like that.
There are many cubic coordinate systems and many axial ones. In this guide, I will not cover all combinations. I will choose two variables, q (column) and r (row). In the circuits in this article, q corresponds to x and r corresponds to z , but this mapping is arbitrary because you can rotate and rotate the circuits to get different mappings.
The advantage of this system over displacement grids is the greater clarity of the algorithms. The downside of the system is that storing a rectangular map is a little weird; see the section on saving maps. Some algorithms are even clearer in cubic coordinates, but since we have the condition x + y + z = 0 , we can calculate the third implied coordinate and use it in these algorithms. In my projects, I call the axes q , r , s , so the condition looks like q + r + s = 0 , and I can calculate s = -q - r when needed.
Axis is the direction in which the corresponding coordinate is incremented. The perpendicular to the axis is the line on which the coordinate remains constant. The grid diagrams above show perpendicular lines.
Axial coordinates are closely related to cubic coordinates, so the conversion is simple:
# convert cubic to axial coordinates q = x r = z # convert axial to cubic coordinates x = q z = r y = -x-z
In code, these two functions can be written as follows:
Function cube_to_hex(h): # axial var q = h.x var r = h.z return Hex(q, r) function hex_to_cube(h): # cube var x = h.q var z = h.r var y = -x-z return Cube(x, y ,z)
Offset coordinates are quite a bit more complicated:
Var directions = [ Cube(+1, -1, 0), Cube(+1, 0, -1), Cube(0, +1, -1), Cube(-1, +1, 0), Cube( -1, 0, +1), Cube(0, -1, +1) ] function cube_direction(direction): return directions function cube_neighbor(hex, direction): return cube_add(hex, cube_direction(direction))
Var directions = [ Hex(+1, 0), Hex(+1, -1), Hex(0, -1), Hex(-1, 0), Hex(-1, +1), Hex(0, +1) ] function hex_direction(direction): return directions function hex_neighbor(hex, direction): var dir = hex_direction(direction) return Hex(hex.q + dir.q, hex.r + dir.r)
As before, we create a table of numbers to add to col and row . However, this time we will have two arrays, one for odd columns/rows and one for even ones. Look at (1,1) in the grid map above and notice how col and row change as you move in each of the six directions. Now let's repeat the process for (2,2) . Tables and code will be different for each of the four types of displacement grids, here is the corresponding code for each type of grid.
odd-r
var directions = [ [ Hex(+1, 0), Hex(0, -1), Hex(-1, -1), Hex(-1, 0), Hex(-1, +1), Hex(0 , +1) ], [ Hex(+1, 0), Hex(+1, -1), Hex(0, -1), Hex(-1, 0), Hex(0, +1), Hex( +1, +1) ] ] function offset_neighbor(hex, direction): var parity = hex.row & 1 var dir = directions return Hex(hex.col + dir.col, hex.row + dir.row)
Even-r
var directions = [ [ Hex(+1, 0), Hex(+1, -1), Hex(0, -1), Hex(-1, 0), Hex(0, +1), Hex(+1 , +1) ], [ Hex(+1, 0), Hex(0, -1), Hex(-1, -1), Hex(-1, 0), Hex(-1, +1), Hex (0, +1) ] ] function offset_neighbor(hex, direction): var parity = hex.row & 1 var dir = directions return Hex(hex.col + dir.col, hex.row + dir.row)
Grid for even (EVEN) and odd (ODD) rows
odd-q
var directions = [ [ Hex(+1, 0), Hex(+1, -1), Hex(0, -1), Hex(-1, -1), Hex(-1, 0), Hex(0 , +1) ], [ Hex(+1, +1), Hex(+1, 0), Hex(0, -1), Hex(-1, 0), Hex(-1, +1), Hex (0, +1) ] ] function offset_neighbor(hex, direction): var parity = hex.col & 1 var dir = directions return Hex(hex.col + dir.col, hex.row + dir.row)
Even-q
var directions = [ [ Hex(+1, +1), Hex(+1, 0), Hex(0, -1), Hex(-1, 0), Hex(-1, +1), Hex(0 , +1) ], [ Hex(+1, 0), Hex(+1, -1), Hex(0, -1), Hex(-1, -1), Hex(-1, 0), Hex (0, +1) ] ] function offset_neighbor(hex, direction): var parity = hex.col & 1 var dir = directions return Hex(hex.col + dir.col, hex.row + dir.row)
Grid for even (EVEN) and odd (ODD) columns
Var diagonals = [ Cube(+2, -1, -1), Cube(+1, +1, -2), Cube(-1, +2, -1), Cube(-2, +1, +1 ), Cube(-1, -1, +2), Cube(+1, -2, +1) ] function cube_diagonal_neighbor(hex, direction): return cube_add(hex, diagonals)
As before, we can convert these coordinates to axial coordinates by dropping one of the three coordinates, or convert to offset coordinates by precomputing the results.
Function cube_distance(a, b): return (abs(a.x - b.x) + abs(a.y - b.y) + abs(a.z - b.z)) / 2
The equivalent of this notation would be to say that one of the three coordinates must be the sum of the other two, and then get that as a distance. You can choose the bisection form or the maximum value form below, but they give the same result:
Function cube_distance(a, b): return max(abs(a.x - b.x), abs(a.y - b.y), abs(a.z - b.z))
In the figure, the maximum values are highlighted in color. Notice also that each color represents one of the six "diagonal" directions.
gif
Function hex_distance(a, b): var ac = hex_to_cube(a) var bc = hex_to_cube(b) return cube_distance(ac, bc)
If the compiler in your case embeds (inline) hex_to_cube and cube_distance , then it will generate code like this:
Function hex_distance(a, b): return (abs(a.q - b.q) + abs(a.q + a.r - b.q - b.r) + abs(a.r - b.r)) / 2
There are many different ways to write the distances between hexagons in axial coordinates, but regardless of how you write the distance between hexagons in the axial system is derived from the Manhattan distance in the cubic system. For example, the described "difference of differences" is obtained by writing a.q + a.r - b.q - b.r as a.q - b.q + a.r - b.r and using the maximum value form instead of the bisection form cube_distance . All of them are similar if you see the connection with cubic coordinates.
Function offset_distance(a, b): var ac = offset_to_cube(a) var bc = offset_to_cube(b) return cube_distance(ac, bc)
We will use the same pattern for many algorithms: convert from hexagons to cubes, run the cubic version of the algorithm, and convert the cubed results to hexagon coordinates (axial or offset coordinates).
gif
Function lerp(a, b, t): // for floats return a + (b - a) * t function cube_lerp(a, b, t): // for hexagons return Cube(lerp(a.x, b.x, t), lerp(a.y, b.y, t), lerp(a.z, b.z, t)) function cube_linedraw(a, b): var N = cube_distance(a, b) var results = for each 0 ≤ i ≤ N: results.append( cube_round(cube_lerp(a, b, 1.0/N * i))) return results
Notes:
We can work backwards from the hexagon distance formula distance = max(abs(dx), abs(dy), abs(dz)) . To find all hexagons within N , we need max(abs(dx), abs(dy), abs(dz)) ≤ N . This means that all three values are needed: abs(dx) ≤ N and abs(dy) ≤ N and abs(dz) ≤ N . Removing the absolute value gives -N ≤ dx ≤ N and -N ≤ dy ≤ N and -N ≤ dz ≤ N . In code, this will be a nested loop:
Var results = for each -N ≤ dx ≤ N: for each -N ≤ dy ≤ N: for each -N ≤ dz ≤ N: if dx + dy + dz = 0: results.append(cube_add(center, Cube(dx , dy, dz)))
This loop will work, but will be rather inefficient. Of all the values of dz that we iterate over in the loop, only one actually satisfies the condition of cubes dx + dy + dz = 0 . Instead, we will directly calculate the value of dz that satisfies the condition:
var results = for each -N ≤ dx ≤ N: for each max(-N, -dx-N) ≤ dy ≤ min(N, -dx+N): var dz = -dx-dy results.append(cube_add( center, Cube(dx, dy, dz)))
This loop goes through only the required coordinates. In the figure, each range is a pair of lines. Each line is an inequality. We take all hexagons that satisfy six inequalities.
gif
One can approach this problem from the point of view of algebra or geometry. Algebraically, each area is expressed as inequality conditions of the form -N ≤ dx ≤ N , and we need to find the intersection of these conditions. Geometrically, each area is a cube in 3D space, and we will intersect two cubes in 3D space to get a cuboid in 3D space. We then project it back onto the x + y + z = 0 plane to get the hexagons. I will solve this problem algebraically.
First, we rewrite the condition -N ≤ dx ≤ N in the more general form x min ≤ x ≤ x max , and take x min = center.x - N and x max = center.x + N . Let's do the same for y and z , resulting in a general view of the code from the previous section:
Var results = for each xmin ≤ x ≤ xmax: for each max(ymin, -x-zmax) ≤ y ≤ min(ymax, -x-zmin): var z = -x-y results.append(Cube(x, y, z))
The intersection of two ranges a ≤ x ≤ b and c ≤ x ≤ d is max(a, c) ≤ x ≤ min(b, d) . Since the area of hexagons is expressed as ranges over x , y , z , we can individually intersect each of the ranges x , y , z , and then use a nested loop to generate a list of hexagons at the intersection. For one area of hexagons, we take x min = H.x - N and x max = H.x + N , similarly for y and z . For the intersection of two hexagon areas, we take x min = max(H1.x - N, H2.x - N) and x max = min(H1.x + N, H2.x + N), similarly for y and z . The same pattern works for the intersection of three or more regions.
gif
Function cube_reachable(start, movement): var visited = set() add start to visited var fringes = fringes.append() for each 1< k ≤ movement: fringes.append() for each cube in fringes: for each 0 ≤ dir < 6: var neighbor = cube_neighbor(cube, dir) if neighbor not in visited, not blocked: add neighbor to visited fringes[k].append(neighbor) return visited
Rotating 60° to the right shifts each coordinate one position to the right:
[x, y, z] to [-z, -x, -y]
Rotating 60° to the left shifts each coordinate one position to the left:
[x, y, z] to [-y, -z, -x]
Here is the complete sequence of rotating position P around center position C, resulting in a new position R:
Function cube_ring(center, radius): var results = # this code doesn't work for radius == 0; do you understand why? var cube = cube_add(center, cube_scale(cube_direction(4), radius)) for each 0 ≤ i< 6:
for each 0 ≤ j < radius:
results.append(cube)
cube = cube_neighbor(cube, i)
return results
In this code, the cube starts at the ring, shown as a large arrow from the center to the corner of the diagram. I chose angle 4 to start with because it corresponds to the path my direction numbers travel. You may need a different starting angle. At each stage of the inner loop, the cube moves one hexagon around the ring. After 6 * radius steps, he ends up where he started.
Function cube_spiral(center, radius): var results = for each 1 ≤ k ≤ radius: results = results + cube_ring(center, k) return results
Traversing hexagons in this way can also be used to calculate the range of motion (see above).
This algorithm can be slow over large areas, but it is easy to implement, so I recommend starting with it.
gif
I want to expand this guide further. I have