Search code examples
wolfram-mathematica

how to draw a triangular grid of length n in mathematica


I am wondering if anyone could please help to draw a triangular grid (equilateral) with edge length n in mathematica. Thanks.


Solution

  • A Simple Grid:

    p = Table[ Table[
    
        Polygon[{j - 1/2 i, i Sqrt[3]/2} + # & /@ {{0, 0}, {1/2,Sqrt[3]/2}, {1, 0}}],
    
        {j, i, 9}], {i, 0, 9}];
    
    Graphics[{EdgeForm[Black], FaceForm[White], p}]  
    

    Triangular Grid

    Edit

    A more clear version, I guess:

    s3 = Sqrt[3];
    templateTriangleVertex = {{0, 0}, {1, s3}, {2, 0}};
    
    p = Table[Table[
    
        Polygon[{2 j - i, s3 i } + # & /@ templateTriangleVertex],
    
        {j, i, 9}], {i, 0, 9}];
    
    Graphics[{EdgeForm[Black], FaceForm[White], p}]