Graphics, Figures & TablesDrawing a Hex Board

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
surculus
Posts: 3
Joined: Mon Sep 16, 2013 8:30 pm

Drawing a Hex Board

Post by surculus »

Hi,

I need to draw up a Hex board, and am having problems with it. I need to draw it in its conventional form and also in John Nash's form.

I did find the hexgame package that simplifies the drawing in its conventional form. However, when I try using it there is just a huge red box with a black outline. Perhaps because this is from 2006? I also found a code sample here.

Code: Select all

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes}

\begin{document}
  \begin{tikzpicture}[
    hexa/.style={ 
      shape=regular polygon,
      regular polygon sides=6,
      minimum size=1cm,
      draw,
      inner sep=0,
      anchor=south,
      fill=lightgray!85!blue,
      rotate=30
    }
  ]
    \foreach \j in {0,...,5}{%
      \pgfmathsetmacro\end{5+\j} 
      \foreach \i in {0,...,\end}{%
        \node[hexa] (h\i;\j) at ({(\i-\j/2)*sin(60)},{\j*0.75}) {};
      }
    }
    \foreach \j in {0,...,4}{%
      \pgfmathsetmacro\end{9-\j} 
      \foreach \i in {0,...,\end}{%
        \pgfmathtruncatemacro\k{\j+6}  
        \node[hexa] (h\i;\k) at ({(\i+\j/2-2)*sin(60)},{4.5+\j*0.75}) {};
      }
    }
    \foreach \k in {0,...,10} {%
      \node[circle,red,minimum size=1cm] at (h3;\k) {3;\k};
    }
    \foreach \k in {0,...,10} {%
      \node[circle,blue,minimum size=1cm] at (h1;\k) {1;\k};
    }
  \end{tikzpicture}
\end{document}
I tried modifying it such that it would look like a traditional Hex board, but it gets very weird when you mess with the variables.

I would also like to draw a Hex game like John Nash played it. This is basically just a grid. Little dots to mark vertices where the grids cut each other, and lines (edges) between all vertices lying on the same y=x line.

Is there a pre-existing way, or rather an easy way to do this? If not, could someone point me to documentation on how to do this?

Thanks!
Last edited by localghost on Wed Sep 18, 2013 9:37 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Re: Drawing a Hex Board

Post by Stefan Kottwitz »

Hi surculus,

welcome to the forum!

What exactly do you mean with conventional form and John Nash's form? Perhaps post images as attachments, so we can see what is desired.

Stefan
LaTeX.org admin
surculus
Posts: 3
Joined: Mon Sep 16, 2013 8:30 pm

Drawing a Hex Board

Post by surculus »

Hi

Sorry for the incredibly late reply, had a hiatus in my essay writing..

What I consider a 'conventional' Hex board:
hex-board-conventional.png
hex-board-conventional.png (109.95 KiB) Viewed 6623 times
You may notice that some of the edges are thicker than the others. It would be great if there is a convenient way to make some edges of the board thicker, to signify a path on the 'graph'.

What I meant by John Nash's Hex board:
hex-board-nash.png
hex-board-nash.png (33.26 KiB) Viewed 6623 times
Do you know of any way to do this successfully?


Thanks,
Surculus
Last edited by localghost on Fri Nov 01, 2013 7:05 pm, edited 1 time in total.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Drawing a Hex Board

Post by localghost »

Just for information to other users for awareness of possibly already existing solutions. The question has also been posted to {TeX} SX where it has got many answers from which one has been accepted. Please read what our administrator thinks about that.
Board Rules wrote:A crossposting is always contra-productive. But there is nothing really against it as long as it is mentioned. This means that a direct link has to be added. So other users who want to help are preserved from double efforts and waste of time.
Such kind of x-posting without notification represents a direct violation of our rules and has to be prevented absolutely in future questions.
surculus
Posts: 3
Joined: Mon Sep 16, 2013 8:30 pm

Drawing a Hex Board

Post by surculus »

As localghost said, this has been solved over at stackexchange. Very helpful and insightful comments from anyone who is interested.

Sorry that I did not note the cross-post.
Post Reply