# c.w.chambers

Members

4

139 Neutral

• Rank
Newbie
1. ## C# Path Finding Recommendations

Eric Lippert has a series on his blog where he implements an A* pathfinder in C#. (Bonus: he does so using immutable data structures.) http://blogs.msdn.com/b/ericlippert/archive/2007/10/02/path-finding-using-a-in-c-3-0.aspx http://blogs.msdn.com/b/ericlippert/archive/2007/10/04/path-finding-using-a-in-c-3-0-part-two.aspx http://blogs.msdn.com/b/ericlippert/archive/2007/10/08/path-finding-using-a-in-c-3-0-part-three.aspx http://blogs.msdn.com/b/ericlippert/archive/2007/10/10/path-finding-using-a-in-c-3-0-part-four.aspx
2. ## Barycentric puzzle

Yeah, I may have jumped the fun in my reply. The solution I presented is for transforming points of a Cartesian plane to points of a grid-graph that indexes hexes. Sorry about that. :(
3. ## Barycentric puzzle

If your hexagons are uniform*, and if you don't mind indexing your vertices as elements of an oblique grid-graph, then there is an algebraic solution picking which hex a given point is in. To determine which hex a point lies within one can use the following function for each index-coordinate: floor((floor(f(x,y))+floor(g(x,y)))/3), where ‘f’ and ‘g’ and linear transformations such that neither ‘f+g=0’ nor ‘f-g=0’ are not true. Alternatively you could combine the functions into a matrix and supply the function the resulting points ‘x’ and ‘y’ coordinates in place of the functions ‘f’ and ‘g’, respectively. For each index-coordinate there is a different set of transformations. One can determine these transformations by observing that by picking two adjacent edges of your zero-hex, ‘(0,0)’ and determining the implicit forms of the lines on which these edges lies, that one determines both the lower zig-zag edge of the of a row of hexes in which the zero-hex lies, and the implicit-forms of the lines are implicit-functions that determine the transformations. A quick example. Suppose we align the grid-vertices such that the zero-vertex coincides with the origin and the vertex indexed (1,0) coincides with the same point of the plane. This centers the zero-hex at (0,0) and the hex indexed as (1,0) centered at the same point. If one wants rows that run parallel to the x-axis and with indexes rising in the positive y-direction, then pick the vertex of the zero-hexagon which lies on the y-axis below the x-axis as a point lying on the lower edge of the hex row, the two edges of the hex which share that vertex are the edges which determine the transformation. In this case those functions are: f(x) = x+sqrt(3)*y+1, and g(x) = -x+sqrt(3)*y+1. You can see the result of this here on Wolfram Alpha: http://m.wolframalpha.com/input/?i=plot%E2%8C%8A%28%E2%8C%8Ax%2B%E2%88%9A%283%29y%2B1%E2%8C%8B%2B%E2%8C%8A-x%2B%E2%88%9A%283%29y%2B1%E2%8C%8B%29%2F3%E2%8C%8B+x%3D-1.5..1.5+y%3D-1.5..1.5&x=0&y=0 This might be overkill for what you need as it is a general hex-picking solution, but you might be able to adapt it to your needs. Hope that helps.
4. ## Mathbook for dummies, any recomendation?

For a short concise read I'd recommend the following: http://www.amazon.com/gp/aw/d/0486636348