public CartesianCoord GetHexCorner(CartesianCoord center, double size, int corner) { var angle_deg = 60 * corner + 30; var angle_rad = Math.PI / 180 * angle_deg; return(new CartesianCoord(center.X + size * Math.Cos(angle_rad), center.Y + size * Math.Sin(angle_rad))); }
public Vertex(CartesianCoord cellCenter, double cellSize, int corner, Orientation orientation = Orientation.Horizontal) { var angle_deg = 60 * corner + (30 * (int)orientation); var angle_rad = Math.PI / 180 * angle_deg; Center = new CartesianCoord(cellCenter.X + cellSize * Math.Cos(angle_rad), cellCenter.Y + cellSize * Math.Sin(angle_rad)); }
public static CartesianCoord GetHexCorner(CartesianCoord center, double size, int corner) { var degrees = 60 * corner + 30; var radians = Math.PI / 180 * degrees; return(new CartesianCoord(center.X + size * Math.Cos(radians), center.Y + size * Math.Sin(radians))); }
public Channel(CartesianCoord origin, CartesianCoord end) { Origin = origin; End = end; Path = new Line() { X1 = origin.X, Y1 = origin.Y, X2 = end.X, Y2 = end.Y }; }
public bool IsConcentricWith(CartesianCoord coordinate) { var check = (Math.Abs(X - coordinate.X) / X < 0.01 && Math.Abs(Y - coordinate.Y) / Y < 0.01); //if (check) // Console.WriteLine("Within Limits: DX = " + (X - coordinate.X) / X + ", DY = " + (Y - coordinate.Y) / Y); //else // Console.WriteLine("Outside Limits: DX = " + (X - coordinate.X) / X + ", DY = " + (Y - coordinate.Y) / Y); return(Math.Abs(X - coordinate.X) / X < 0.01 && Math.Abs(Y - coordinate.Y) / Y < 0.01); }
//public DisplayController DisplayController = new DisplayController(); #region Constructors public HexGrid(int columnCount, int rowCount, int cellSize, CartesianCoord gridOrigin, Orientation orientation = Orientation.Horizontal) { VertexCounter = 0; GridLines = new List <Line>(); ColumnCount = columnCount; RowCount = rowCount; //var y = (orientation == Orientation.Horizontal) ? rowCount : columnCount; //var x = (orientation == Orientation.Horizontal) ? columnCount : rowCount; //Generate all Vertices var vertices = new List <Vertex>(); var channels = new List <Channel>(); double xSpacing; double ySpacing; for (int i = 0; i < rowCount; i++) { var parity = i % 2; xSpacing = 2 * cellSize * Math.Cos(Math.PI / 180 * 30); ySpacing = xSpacing * Math.Cos(Math.PI / 180 * 30); for (int j = 0; j < columnCount; j++) { for (int n = 0; n < 6; n++) { CartesianCoord coord; if (orientation == Orientation.Vertical) { coord = new CartesianCoord(gridOrigin.X + (parity * xSpacing / 2) + xSpacing * j, gridOrigin.Y + i * ySpacing); } else { coord = new CartesianCoord(gridOrigin.Y + i * ySpacing, gridOrigin.X + (parity * xSpacing / 2) + xSpacing * j); } var vertex = new Vertex(coord, cellSize, n, orientation); if (!vertices.Any(v => v.IsConcentricWith(vertex))) { vertices.Add(vertex); VertexCounter++; vertex.Id = VertexCounter; } var nextCorner = new Vertex(coord, cellSize, n + 1, orientation); var channel = new Channel(vertex, nextCorner); if (!channels.Any(c => c.IsCoherentWith(channel))) { channels.Add(channel); ChannelCounter++; channel.Id = ChannelCounter; } } } } AllVertices = vertices; AllChannels = channels; //Generate all Channels/Lines/Connectors (come up with a name) }
//TODO: Creating a cell should: //1. Create the walls and add the unique ones to the list of walls //2. Create the vertices and add the unique ones to the list of vertices //3. Create an enum for labelling the Cell Vertices (Ortho, Para, Meta, Normal, Anti-Ortho, Anti-Meta) //4. Create an enum for labelling the Cell Walls, among other things (use Quark types for directions) public Cell(CartesianCoord center, int cellSize, Orientation orientation, HexGrid hexGrid) { Center = center; for (int i = 0; i < 6; i++) { var origin = new Vertex(center, cellSize, i); //CellFactory.AddToVertices(hexGrid, this, origin.Center); var end = new Vertex(center, cellSize, i + 1); hexGrid.AddToVertices(end); var wall = new CellWall(origin, end); hexGrid.AddToCellWalls(wall); } }
public CellWall(CartesianCoord origin, CartesianCoord end) { Origin = origin; End = end; }