public double GetAngle(Hex.CubeCoordinates sourceCoordinates, Hex.CubeCoordinates targetCoordinates) { double dx = this.HexGrid.HexToPixel(targetCoordinates).X - this.HexGrid.HexToPixel(sourceCoordinates).X; double dy = this.HexGrid.HexToPixel(targetCoordinates).Y - this.HexGrid.HexToPixel(sourceCoordinates).Y; return(Math.Atan2(dy, dx) * 180 / Math.PI); }
public TPoint HexToPixel(CubeCoordinates h) { double x = (_orientation.f0 * h.Q + _orientation.f1 * h.R) * s_Policy.GetX(_size); double y = (_orientation.f2 * h.Q + _orientation.f3 * h.R) * s_Policy.GetY(_size); return(s_Policy.Create(x + s_Policy.GetX(_origin), y + s_Policy.GetY(_origin))); }
public IPoint HexToPixel(CubeCoordinates h) { double x = (_orientation.f0 * h.Q + _orientation.f1 * h.R) * _size.X; double y = (_orientation.f2 * h.Q + _orientation.f3 * h.R) * _size.Y; return(new Point(x + _origin.X, y + _origin.Y)); }
public bool AreNeighbors(Hex.CubeCoordinates firstHexagon, Hex.CubeCoordinates secondHexagon) { for (int i = 0; i < 6; i++) { if (Hex.CubeCoordinates.Neighbor(firstHexagon, i).Equals(secondHexagon)) { return(true); } } return(false); }
public IList <TPoint> PolygonCorners(CubeCoordinates h) { var corners = new List <TPoint>(6); var center = HexToPixel(h); for (int i = 0; i < 6; i++) { var offset = HexCornerOffset(i); corners.Add(s_Policy.Add(center, offset)); } return(corners); }
static public IList <CubeCoordinates> HexLinedraw(CubeCoordinates a, CubeCoordinates b) { int n = CubeCoordinates.Distance(a, b); var a_nudge = new CubeFractionCoordinates(a.Q + 0.000001, a.R + 0.000001, a.S - 0.000002); var b_nudge = new CubeFractionCoordinates(b.Q + 0.000001, b.R + 0.000001, b.S - 0.000002); var results = new List <CubeCoordinates> { }; double step = 1.0 / Math.Max(n, 1); for (int i = 0; i <= n; i++) { results.Add(HexLerp(a_nudge, b_nudge, step * i).Round()); } return(results); }
public OffsetCoordinates ToOffsetCoordinates(CubeCoordinates h) { int column; int row; switch (_orientation.name) { case OrientationName.FlatHexagons: column = h.Q; row = h.R + ((h.Q + _offset.Value * (h.Q & 1)) / 2); return(new OffsetCoordinates(column, row)); case OrientationName.PointyHexagons: column = h.Q + ((h.R + _offset.Value * (h.R & 1)) / 2); row = h.R; return(new OffsetCoordinates(column, row)); default: throw new NotImplementedException(); } }
public static int Distance(CubeCoordinates a, CubeCoordinates b) { return((a - b).Length); }
public static CubeCoordinates DiagonalNeighbor(CubeCoordinates hex, int direction) { return(hex + Diagonals[direction]); }
static public CubeCoordinates Neighbor(CubeCoordinates hex, int direction) { return(hex + Directions[direction]); }
public int GetDistance(Hex.CubeCoordinates firstHexagon, Hex.CubeCoordinates secondHexagon) { return(Hex.CubeCoordinates.Distance(firstHexagon, secondHexagon)); }