public TriangularLattice(BaseGrid grid, Orientation orientation, LatticeTypeEnum latticeType)
        {
            init(grid, orientation, latticeType);
            double xPos = -grid.OriginX + (Hex.UnitWidth / 2);
            double yPos = (_lineCount * Hex.UnitHeight / 2);
            int    i    = 0;
            double z    = -Math.Floor(_lineCount / 2);

            while (yPos >= (-grid.OriginY))
            {
                double x = calculateBaseXCoordinate(i);
                double y = -x - z;
                while (xPos <= (grid.OriginX))
                {
                    var labelText = siteId + ": " + x + ", " + y + ", " + z;
                    var location  = orientation == Orientation.Horizontal ? new CartesianCoord(xPos, yPos) : new CartesianCoord(yPos, xPos);
                    createNewSite(latticeType, x, y, z, labelText, location);
                    xPos += Hex.UnitWidth;
                    x++;
                    y--;
                }
                i++;
                xPos  = (-grid.OriginX) + ((Hex.UnitWidth / 2) * (i % 2));
                yPos -= Hex.UnitHeight;
                z++;
            }
        }
        private void addShell(int shellNumber, LatticeTypeEnum latticeType)
        {
            var siteCount = edgeSiteCount(shellNumber);

            for (int i = 0; i < siteCount; i++)
            {
                addSite(shellNumber, siteCount, i, siteId++, latticeType);
            }
        }
 public TriangularLattice(BaseGrid grid, int size, Orientation orientation, LatticeTypeEnum latticeType)
 {
     Grid        = grid;
     Size        = size;
     Orientation = orientation;
     for (int i = 0; i <= Size; i++)
     {
         addShell(i, latticeType);
     }
 }
 private void init(BaseGrid grid, Orientation orientation, LatticeTypeEnum latticeType)
 {
     Grid = grid;
     grid.Canvas.MouseDown += canvasClick;
     Orientation            = orientation;
     Sites      = new Dictionary <int, Site>();
     Cursors    = new Ellipse[3];
     GridLines  = new Dictionary <int, HexLine>();
     _numerator = orientation == Orientation.Horizontal ? grid.Height : grid.Width;
     _lineCount = getMaximumLineCount(_numerator);
 }
        private void createNewSite(LatticeTypeEnum latticeType, double x, double y, double z, string labelText, CartesianCoord location)
        {
            var site  = new Site(location, siteId++, x, y, z, latticeType);
            var label = new TextBlock()
            {
                FontSize = 10, Text = labelText
            };

            //Console.WriteLine(labelText);
            AddToXRanks(site);
            AddToYRanks(site);
            AddToZRanks(site);
            Grid.AddShape(site.Marker, location);
            Grid.Add(label, location);
            Sites.Add(site.Id, site);
        }
        public TriangularLattice(BaseGrid grid, Orientation orientation, LatticeTypeEnum latticeType, bool alt)
        {
            init(grid, orientation, latticeType);
            double z = Math.Floor(_lineCount / 2);
            //TODO: Swap out the "xPos and yPos variables + while loops" with "cell limit per row + for loop"
            double yPos = (_lineCount * Hex.UnitHeight / 2);
            double xPos = -grid.OriginX + ((Hex.UnitWidth / 2) * Math.Abs(z % 2));

            while (yPos >= (-grid.OriginY))
            {
                double x = calculateBaseXCoordinate(z);
                double y = -x - z;
                while (xPos <= (grid.OriginX))
                {
                    var labelText   = siteId + ": " + x + ", " + y + ", " + z;
                    var hexLocation = new HexCoord(x, y, z);
                    var location    = hexLocation.ToCartesian();
                    //var location2 = orientation == Orientation.Horizontal ? new CartesianCoord(xPos, yPos) : new CartesianCoord(yPos, xPos);
                    //if (siteId == 25 || siteId == 7)
                    //{

                    //}
                    //Console.WriteLine(labelText + " [" + xPos + "<" + grid.OriginX + "]");
                    createNewSite(latticeType, x, y, z, labelText, location);

                    xPos += Hex.UnitWidth;
                    //if (xPos > grid.OriginX)
                    //Console.WriteLine(xPos + ">" + grid.OriginX + "----");
                    x++;
                    y--;
                }
                xPos  = (-grid.OriginX) + ((Hex.UnitWidth / 2) * Math.Abs((1 + z) % 2));
                yPos -= Hex.UnitHeight;
                z--;
            }
        }
        private CartesianCoord GetCoordForSite(int shellNumber, int shellSiteCount, int shellSiteId, LatticeTypeEnum latticeType)
        {
            var radians         = ((2 * Math.PI) / shellSiteCount) * shellSiteId;
            var internalRadians = radians % (Math.PI / 3);
            var radius          = shellNumber * Constants.UnitLength;
            //cos(a-b) = cos(a)cos(b) + sin(a)sin(b)
            //a = Math.PI / 6
            //b = internalRadians
            var cos30     = Math.Sqrt(3) / 2;
            var sin30     = 0.5;
            var hexRadius = (radius * cos30) / (
                (cos30 * Math.Cos(internalRadians)) + (sin30 * Math.Sin(internalRadians))
                );
            //var adjustment = 2 * (int)latticeType * (Constants.UnitLength / 3);
            var xCoord = hexRadius * Math.Cos(radians);
            var yCoord = hexRadius * Math.Sin(radians); //+ adjustment;

            Console.WriteLine((siteId - 1) + "\t[" + shellNumber + "," + shellSiteId + "]\t" + xCoord + "\t" + yCoord);
            return(Orientation == Orientation.Horizontal ? new CartesianCoord(xCoord, yCoord) : new CartesianCoord(yCoord, xCoord));
        }
 private void addSite(int shellNumber, int shellSiteCount, int shellSiteId, int siteId, LatticeTypeEnum latticeType)
 {
     var location = GetCoordForSite(shellNumber, shellSiteCount, shellSiteId, latticeType);
     //var site = new Site(location, siteId, latticeType);
     //var label = new TextBlock() { FontSize = 20, Text = siteId.ToString() };
     ////Grid.Add(label, location.X, location.Y);
     //Grid.Add(site.Marker, location.X, location.Y);
 }