How to make hexagons: Difference between revisions
m
Rename images and add link
-u ndefined- (talk | contribs) (Adapted from old article by LukaszM) |
-u ndefined- (talk | contribs) m (Rename images and add link) |
||
Line 5: | Line 5: | ||
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: | 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 [[vector]]s to the position of the original piece: | 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 [[vector]]s to the position of the original piece: | ||
* (-0.317, 0, 0.183), | * <code>(-0.317, 0, 0.183)</code>, | ||
* (-0.317, 0, 0.549), | * <code>(-0.317, 0, 0.549)</code>, | ||
* (0, 0, 0.732), | * <code>(0, 0, 0.732)</code>, | ||
* (0.317, 0, 0.183), | * <code>(0.317, 0, 0.183)</code>, | ||
* (0.317, 0, 0.549). | * <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): | 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°, 120° etc) and for that, we're going to use the [[Make Rotation]] block. The loop looks like this: | 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°, 120° 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! | Let's start the script now. See what happened to our original object! | ||
{{Image|Hexagon hexagon.png}} | |||
Here we go! A perfect regular hexagon! | Here we go! A perfect regular hexagon! | ||
Line 41: | Line 41: | ||
This is how it looks in Fancade. Here we use the fact that cotangent of an angle is equal to its [[Cos|cosine]] divided by its [[Sin|sine]]: | This is how it looks in Fancade. Here we use the fact that cotangent of an angle is equal to its [[Cos|cosine]] divided by its [[Sin|sine]]: | ||
{{Image|Hexagon advanced calculate offset.png}} | |||
Now, to calculate the positions of the remaining pieces, we can subtract '''A''' from the position of the original object and then add '''A''' rotated by a certain angle. Here's how it looks: | Now, to calculate the positions of the remaining pieces, we can subtract '''A''' from the position of the original object and then add '''A''' rotated by a certain angle. Here's how it looks: | ||
{{Image|Hexagon advanced calculate position.png}} | |||
For '''N''' = 6 and '''X''' = '''Z''' = 1, we obtain the exact same hexagon as in the classic method, without using any additional lists! After changing the value of '''N''', we can obtain different polygons, for instance a pentagon: | For '''N''' = 6 and '''X''' = '''Z''' = 1, we obtain the exact same hexagon as in the classic method, without using any additional lists! After changing the value of '''N''', we can obtain different polygons, for instance a pentagon: | ||
{{Image|Hexagon advanced 5 sides.png}} | |||
If '''N''' 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 '''X''' and '''Z'''. | If '''N''' 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 '''X''' and '''Z'''. | ||
{{Image|Hexagon advanced 8 sides.png}} | |||
[[Category:Scripting]] | [[Category:Scripting]] |