designcoding
About Table of Contents Keywords Monthly Archive
Support designcoding!

Hexagonal grid with Rhino Python

July 25, 2017 | Algorithms
#grid #hexagon #rhino-python

This python code proves how much effort it takes to create a simple hexagonal tessellation. There are, of course, much easier and faster methods than this. But here you see a code that introduces students to Rhino Python. Using this code, a new Rhino command can be generated, and for the first time in Rhino, we can have a command that creates a hexagonal grid. I followed this tutorial to turn this Python script into a Rhino command. This is also educational. Because I sometimes want my design mathematics students to mimic a Rhino command in Python. Then, I ask them to improve one of the commands. This is a nice example of further improvements. A student can follow this and lead the hexagonal grid code to a hexagonal array command, for example.

Hexagonal grid with Rhino Python grid, hexagon

The below Python code uses the rhinoscriptsyntax module to draw the hexagonal grid. As you can read, it draws the hexagons by dividing a circle. Because Rhino Python in 2017 doesn’t have a polygon method. I hope in the future, this might be solved. However, it is a good exercise to include a polygon method in this script. After defining a function that draws the polygon, the script uses it iteratively to create the grid.
I will try to publish and explain this as soon as possible. Also, I think that this and some other commands can be a plug-in in the future. There are many lunchbox plug-ins out there. But why not I shouldn’t code my own version.

# Draw centered hexagonal grid
# 25.07.2017 www.designcoding.net - Tugrul Yazar
import rhinoscriptsyntax as rs
import math
hexGridCenter = rs.GetPoint("Specify center point")
hexGridExtend = rs.GetInteger("Enter the number of radial levels", 3, 2)
hexGridClSize = rs.GetReal("Edge size of hexagons", 1.0)
hexGridCAngle = rs.GetReal("Rotation angle of hexagons", 0.0)
edges = 6
rs.AddPoint(hexGridCenter)
hexGrid = []
pythagoras = 2 * math.sqrt((hexGridClSize * hexGridClSize) - ((hexGridClSize / 2) * (hexGridClSize / 2)))
def polygon(center,edges,size,angle):
tempCircle = rs.AddCircle(center, size)
tempPoints = rs.DivideCurve(tempCircle, edges, create_points=False, return_points=True)
tempPoints.append(tempPoints[0])
tempHexago = rs.AddPolyline(tempPoints)
tempReturn = rs.RotateObject(tempHexago, center, angle, axis=None, copy=False)
rs.DeleteObject(tempCircle)
return tempReturn
for i in range(0, hexGridExtend):
tempSize = pythagoras * (i + 1)
dut = polygon(hexGridCenter, edges, tempSize, 30 + hexGridCAngle)
temp = rs.DivideCurve(dut, (i+1) * edges, create_points=False, return_points=True)
rs.DeleteObject(dut)
hexGrid.extend(temp)
for i in range(0, len(hexGrid)):
polygon(hexGrid[i], edges, hexGridClSize, hexGridCAngle)
rs.AddPoint(hexGrid[i])

Python file (PY)Download

Cite this post

Yazar, T. (2017, July 25). Hexagonal grid with Rhino Python. designcoding. Retrieved December 3, 2026, from https://www.designcoding.net/hexagonal-grid-with-rhino-python/

Related Posts

Waterbomb Tessellation

January 23, 2013

It all started with my new passion for origami tessellations, not much of origami, but the tessellation part. I was too lazy to fold it physically, nor model them using an engine such as Kangaroo. That would also be very unnecessary (and yes, very boring) to simulate a folding effort on the computer unless we lose our connection with the real world. Instead, I tried to look at a much more abstract, silly, and basic part of it; the creasing…

Vector Fields

December 28, 2012

Back to the basics. I finally had time to test the vector fields components in Grasshopper. It was a couple of updates ago, a new tool group emerged in the vector tab, introducing different types of vector fields to users. Then, these fields could be merged to form more complex effects. However, I created a very simple example of how we can use those components to distort a system (such as a regular tessellation).  Using attractor forces (usually in geometric…

Hexagonal Star Pattern

November 14, 2026

Sharing the latest scary pattern from my old pattern archive. This time, instead of using Parakeet, I designed it using only standard Grasshopper components. We start with a hexagonal grid. We exploded the cells of this grid and found the midpoint of each edge. By connecting these midpoints, we again created closed polylines. Then, we exploded these closed polylines, turning them into a sequence of data lists. Next, we place a point on each exploded segment (reparameterized with a t-value…

Hexagonal Star Lattice

December 18, 2023

Here are the variations of classical six-pointed star patterns generated by Grasshopper. Generally, you can see these patterns under the title “Islamic patterns” because they are frequent in the decorations of mosques and palaces. I studied these patterns in Grasshopper earlier in these posts. I always find this an interesting geometry exercise. This time, my main goal was to develop a useful code only with the native Grasshopper components that create laser-cut-ready products of hexagonal star lattice. Thus, I made…

Basic Grid Deformation

July 5, 2023

I am still trying to find the simplest solution to some geometric definitions. This is why I called this Grasshopper definition “Basic Grid Deformation”. Here you see the Curve Proximity (CrvProx) component in use. This component calculated the shortest distance between two curves. I think the underpinnings of this component are very interesting. I hope I can code it in Python one day. In order to see the result more clearly, the Previews of the Interpolate Curve (IntCrv) and Square…

  • Chapters

    • Algorithms
    • Discourses
    • Escapes
    • Fabrications
    • Studios
  • Explore

    • Table of Contents
    • Monthly Archive

    • All Keywords
    • #grasshopper
    • #pattern
    • #tutorial
    • #polyhedra
    • #fractal
    • #fourier
    • #simulation
    • #linear-algebra
    • #parametric-curve
    • #bezier-curve
    • #attractor
    • #polygon
    • #design-education
    • #terrain
    • #vector-field
    • #rhinoceros
    • #deformation
    • #vector
    • #chaos
    • #fermat
  • Search

  • Support designcoding!

  • Enjoying designcoding? Support me on Patreon to keep it growing. Thank you!

  • copyright 2026 designcoding.net | about | privacy policy | end user license agreement