HEXAGONS FUN

hexagons are everywhere in nature  , biology , chemistry and computing , the following is from photoscience.com

mathematicaly this more fun because of the intersting applications at programming games giving beautiful math problems to solve (some of them are quite a challenge like  euler project honey comb problem 😛  , or old school Russia math Olympiads )  .

Coordinates for system with  center  the point (0,0)  are :

A1=(L,0)
A2=(L/2, L·√3/2)
A3=(-L/2, L·√3/2)
A4=(-L,0)
A5=(-L/2, -L·√3/2)
A6=(L/2, -L·√3/2)

so at fortran.90  we can take the hexagonal-grid with this code :

&nbsp
1 Program honeycomb
2 !-------------------------------------------
3 ! this program calculates hexagons that look like carbon!
4 implicit none
5 integer :: i,j,N
6 real :: x,y,z
7 open(unit=15,file='carbon-A.dat')
8 N=8
9 z=0.0
10 do i=0,N-1,2
11 do j=0,N-1
12 x=sqrt(3.0)/2.0*real(i)
13 y=j
14 write(15,30) "C",x,y,z
15 x=sqrt(3.0)/2.0*real(i+1)
16 y=j+0.5
17 if (i .ne. N-2) then
18 write(15,30) "C", x,y,z
19 end if
20 enddo
21 close(15)
22 open(unit=16,file='carbon-B.dat')
23 do i=0,N-1,2
24 do j=0,N-1
25 x=sqrt(3.0)/2.0*real(i)
26 y=j
27 if(i .ne. 0) then
28 write(16,30) "C",x-1.0/sqrt(3.0),y,z
29 x=sqrt(3.0)/2.0*real(i+1)
30 y=j+0.5
31 write(16,30) "C",x-1.0/sqrt(3.0),y,z
32 end if
33 enddo
34 enddo
35 close(16)
36 30 format(a6,3f9.5)
37 end program

and will take the following grid :