Making hexagons: Difference between revisions

From Fancade Wiki
(Added category)
m (Redirected page to How to make hexagons)
Tag: New redirect
 
Line 1: Line 1:
This is a tutorial on how to create a perfect regular hexagon in Fancade. This exact method is used to create hexagons in games Hexoban and Hexals.
#REDIRECT [[How to make hexagons]]
 
== Classic method ==
 
Hexagons are made out of 6 square pieces, properly placed, and rotated. First of all, we need to create a square piece. We're going to create a green hexagon with a darker boundary, so our piece looks like this:
 
{{Image|Hexagon Piece.png}}
 
This piece will be copied 5 times and the other pieces will be placed relative to the original one. To obtain the coordinates of the remaining pieces, we need to add the following vectors to the position of the original piece:
* <code>(-0.317, 0, 0.183)</code>,
* <code>(-0.317, 0, 0.549)</code>,
* <code>(0, 0, 0.732)</code>,
* <code>(0.317, 0, 0.183)</code>,
* <code>(0.317, 0, 0.549)</code>.
 
These coordinates are not exact (the exact coordinates are irrational and they require a square root of three), but three decimal places is enough for our hexagon to look good. Let's put them in a [[list]] (starting from index 1 for convenience):
 
{{Image|Hexagon positions.png}}
 
Now our hexagon can be created with a simple loop. We create the remaining pieces and we set their positions using the list above. We also need to rotate them (by 60&deg;, 120&deg; etc) and for that, we're going to use the [[Make Rotation]] block. The loop looks like this:
 
{{Image|Hexagon script.png}}
 
Let's start the script now. See what happened to our original object!
 
{{Image|Hexagon hexagon.png}}
 
Here we go! A perfect regular hexagon!
 
== Advanced method ==
 
Instead of creating the list of positions, they can be calculated in Fancade using trigonometric functions. Using this method, we can also create regular polygons with different number of sides!
 
We need three additional variables. Variable <b>N</b> is the number of sides of our polygon, while <b>X</b> and <b>Z</b> denote the size of our original square object.
 
Now we need to calculate the vector from the origin of our polygon to the origin of our square object. We're going to call it <b>A</b>. Its X and Y coordinates are both equal to 0, while the Z coordinate can be computed using trigonometry:
 
<b>A</b> = (0, 0, 0.5(<b>Z</b> - <b>X</b> · cot(180&deg;/<b>N</b>))).
 
This is how it looks in Fancade. Here we use the fact that cotangent of an angle is equal to its [[cosine]] divided by its [[sine]]:
 
{{Image|???}}
 
Now, to calculate the positions of the remaining pieces, we can subtract <b>A</b> from the position of the original object and then add <b>A</b> [[rotate]]d by a certain angle. Here's how it looks:
 
{{Image|???}}
 
For <b>N</b> = 6 and <b>X</b> = <b>Z</b> = 1, we obtain the exact same hexagon as in the classic method, without using any additional lists! After changing the value of <b>N</b>, we can obtain different polygons, for instance a pentagon:
 
{{Image|???}}
 
If <b>N</b> is bigger than 6, we obtain a polygon with a hole in the middle. To avoid that, we simply need to enlarge our original object and change the values of <b>X</b> and <b>Z</b>.
 
{{Image|???}}
 
[[Category:Building]]

Latest revision as of 12:46, 21 June 2025