Function for a hexagonal 2-dimensional grid

500 Views Asked by At

I can make a "square" $2$D sine wave pattern with the function $f(x,y) = \cos(x) + \cos(y)$:

square grid

What is the function to make a hexagonal pattern of the same kind?

1

There are 1 best solutions below

3
On BEST ANSWER

How about $$ f(x,y) = \cos x + \cos(\tfrac12 x +\tfrac{\sqrt 3}2y)+\cos(\tfrac12 x -\tfrac{\sqrt 3}2y)? $$ See Wolfram Alpha for a plot:

enter image description here

The idea is that $\cos(ax+by)$ will be large when $ax+by\approx 2\pi k$, and small when $ax+by\approx 2\pi k+\frac12$. This means there are periodic stripes of slope $\frac{-a}b$. In my example, the slopes of the stripes of the three summands are $\infty$ (i.e. vertical) and $\pm \frac1{\sqrt3}$, which correspond to making an angle of $\pm 30^\circ$ with the $x$ axis.

A better way of writing the same function is $$ f(x,y) = \cos x + \cos(-\tfrac12 x +\tfrac{\sqrt 3}2y)+\cos(-\tfrac12 x -\tfrac{\sqrt 3}2y) $$ and then noting that the vectors $(1,0),(-\tfrac12, \tfrac{\sqrt 3}2),(-\tfrac12, -\tfrac{\sqrt 3}2)$ are three unit vectors which meet at $120^\circ$ angles at the origin.