N-gon Demo
Updated: 2018-08-24 Added Triangles and a better labelling system
Created a toolbox and script tool for ArcGIS PRO 2.2 on the Code Sharing site... Sampling Grid ....
Yes... 'Pointy' and 'Flat Head' now have a home as well as rectangular sampling grids. I also added cell labelling, akin to how spreadsheet cells are labelled (A1, B1 etc)


: -------------
The Toolbox
Your inputs are simple

For those interested in parameter setup for tools

: -------------
This post .... how to draw octagon or hexagon in ArcGIS desktop ? lead me back to an original post dealing with producing sampling grids.Numpy Snippets # 3 ... Phish_Nyet ... creating sampling grids using numpy and arcpy For completeness, here are further thoughts.
There are two implementations of n-gons...flat topped and pointy topped. They only differ by the rotation angle relative to the X/Y axis. In the case of a square, the rotation is 45°. And yes...even a circle in ArcMap is represented as a 360-sided n-gon so it does have a pointy and a flat top.
Once the seed shape is created, it can be placed around the centroid of known points by creating a polygon from the array outputs. I normally use FeatureclassToNumPyArray and NumPyArrayToFeatureclass to perform the transition from points to array and back again. In my previous blog, I exploited this to produce a sampling grid using rectangles and hexagons of know width, location and orientation for both the flat and pointy topped examples.
There is nothing stopping one from creating any geometric shape in any configuration using these simple principles. All that needs to be determined is the angles needed to produce the n-gon. For example, the only two lines that need to be changed are these to represent the polygon (n-gon) angles. From there, the desired width is used to create the final seed which can then be shifted into the desired configuration/location using other code samples included in my previous blogs.
Flat topped f_rad = np.deg2rad([180.,120.,60.,0.,-60.,-120.,-180.]) angles in degrees
Point topped p_rad = np.deg2rad([150.,90,30.,-30.,-90.,-150.,150.])
See the script with the toolbox on the download site for more complete code samples.
<SPAN class="string token">"""
hexagon_demo_shape.py
Author:
<A class="jive-link-email-small" href="mailto:Dan.Patterson@carleton.ca" rel="nofollow noopener noreferrer" target="_blank">Dan.Patterson@carleton.ca</A>
Purpose: create hexagon shapes in two forms, flat-topped and pointy-topped
Result:
Produce hexagon of desired width in X direction centered about
the origin (0,0)
NOTES: see full code for other implementations
"""</SPAN>
<SPAN class="keyword token">import</SPAN> numpy <SPAN class="keyword token">as</SPAN> np
np<SPAN class="punctuation token">.</SPAN>set_printoptions<SPAN class="punctuation token">(</SPAN>precision<SPAN class="operator token">=</SPAN><SPAN class="number token">4</SPAN><SPAN class="punctuation token">,</SPAN>threshold<SPAN class="operator token">=</SPAN><SPAN class="number token">10</SPAN><SPAN class="punctuation token">,</SPAN>edgeitems<SPAN class="operator token">=</SPAN><SPAN class="number token">5</SPAN><SPAN class="punctuation token">,</SPAN>linewidth<SPAN class="operator token">=</SPAN><SPAN class="number token">75</SPAN><SPAN class="punctuation token">,</SPAN>suppress<SPAN class="operator token">=</SPAN><SPAN class="token boolean">True</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">hex_flat</SPAN><SPAN class="punctuation token">(</SPAN>size<SPAN class="operator token">=</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN>cols<SPAN class="operator token">=</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN>rows<SPAN class="operator token">=</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="string token">"""generate the points for the flat-headed hexagon """</SPAN>
f_rad <SPAN class="operator token">=</SPAN> np<SPAN class="punctuation token">.</SPAN>deg2rad<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">180</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">120</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">60</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="operator token">-</SPAN><SPAN class="number token">60</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="operator token">-</SPAN><SPAN class="number token">120</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="operator token">-</SPAN><SPAN class="number token">180</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN>
X <SPAN class="operator token">=</SPAN> np<SPAN class="punctuation token">.</SPAN>cos<SPAN class="punctuation token">(</SPAN>f_rad<SPAN class="punctuation token">)</SPAN><SPAN class="operator token">*</SPAN>size<SPAN class="punctuation token">;</SPAN> Y <SPAN class="operator token">=</SPAN> np<SPAN class="punctuation token">.</SPAN>sin<SPAN class="punctuation token">(</SPAN>f_rad<SPAN class="punctuation token">)</SPAN><SPAN class="operator token">*</SPAN>size <SPAN class="comment token"># scaled hexagon about 0,0</SPAN>
seed <SPAN class="operator token">=</SPAN> np<SPAN class="punctuation token">.</SPAN>array<SPAN class="punctuation token">(</SPAN>zip<SPAN class="punctuation token">(</SPAN>X<SPAN class="punctuation token">,</SPAN>Y<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># array of coordinates</SPAN>
<SPAN class="keyword token">return</SPAN> seed
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">hex_pointy</SPAN><SPAN class="punctuation token">(</SPAN>size<SPAN class="operator token">=</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN>cols<SPAN class="operator token">=</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN>rows<SPAN class="operator token">=</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="string token">"""pointy hex angles, convert to sin,cos, zip and send"""</SPAN>
p_rad <SPAN class="operator token">=</SPAN> np<SPAN class="punctuation token">.</SPAN>deg2rad<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">150</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">90</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">30</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="operator token">-</SPAN><SPAN class="number token">30</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="operator token">-</SPAN><SPAN class="number token">90</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="operator token">-</SPAN><SPAN class="number token">150</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">150</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN>
X <SPAN class="operator token">=</SPAN> np<SPAN class="punctuation token">.</SPAN>cos<SPAN class="punctuation token">(</SPAN>p_rad<SPAN class="punctuation token">)</SPAN><SPAN class="operator token">*</SPAN>size<SPAN class="punctuation token">;</SPAN> Y <SPAN class="operator token">=</SPAN> np<SPAN class="punctuation token">.</SPAN>sin<SPAN class="punctuation token">(</SPAN>p_rad<SPAN class="punctuation token">)</SPAN><SPAN class="operator token">*</SPAN>size <SPAN class="comment token"># scaled hexagon about 0,0</SPAN>
seed <SPAN class="operator token">=</SPAN> np<SPAN class="punctuation token">.</SPAN>array<SPAN class="punctuation token">(</SPAN>zip<SPAN class="punctuation token">(</SPAN>X<SPAN class="punctuation token">,</SPAN>Y<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">return</SPAN> seed
<SPAN class="keyword token">if</SPAN> __name__ <SPAN class="operator token">==</SPAN> <SPAN class="string token">'__main__'</SPAN><SPAN class="punctuation token">:</SPAN>
flat <SPAN class="operator token">=</SPAN> hex_flat<SPAN class="punctuation token">(</SPAN><SPAN class="number token">700</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">)</SPAN>
pointy <SPAN class="operator token">=</SPAN> hex_pointy<SPAN class="punctuation token">(</SPAN><SPAN class="number token">700</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'\nFlat headed hexagon \n{}'</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>flat<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'\nPointy headed hexagon \n{}'</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>pointy<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>Outputs for flat and pointy headed hexagons.
| 1 m width (unit width) | 100 Unit width | 700 m width |
|---|
Flat headed hexagon [[-1. 0. ] [-0.5 0.866] [ 0.5 0.866] [ 1. 0. ] [ 0.5 -0.866] [-0.5 -0.866] [-1. -0. ]] | Flat headed hexagon [[-100. 0. ] [ -50. 86.6025] [ 50. 86.6025] [ 100. 0. ] [ 50. -86.6025] [ -50. -86.6025] [-100. -0. ]] | Flat headed hexagon [[-700. 0. ] [-350. 606.2178] [ 350. 606.2178] [ 700. 0. ] [ 350. -606.2178] [-350. -606.2178] [-700. -0. ]] |
Flat headed hexagon [[-1. 0. ] [-0.5 0.866] [ 0.5 0.866] [ 1. 0. ] [ 0.5 -0.866] [-0.5 -0.866] [-1. -0. ]] | Pointy headed hexagon [[ -86.6025 50. ] [ 0. 100. ] [ 86.6025 50. ] [ 86.6025 -50. ] [ 0. -100. ] [ -86.6025 -50. ] [ -86.6025 50. ]] | Pointy headed hexagon [[-606.2178 350. ] [ 0. 700. ] [ 606.2178 350. ] [ 606.2178 -350. ] [ 0. -700. ] [-606.2178 -350. ] [-606.2178 350. ]] |
Enjoy. Should one require the rotation code or shape generation code, let me know or check the code for guidance in NumPy Snippets # 3