如何在mathematica中绘制长度为n的三角形网格

发布于 2024-10-13 10:13:07 字数 52 浏览 2 评论 0原文

我想知道是否有人可以帮忙在mathematica中绘制边长为n的三角形网格(等边)。谢谢。

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

高跟鞋的旋律 2024-10-20 10:13:07

简单的网格:

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}]  

三角网格

编辑

更清晰的版本,我猜:

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}]

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}]
巴黎盛开的樱花 2024-10-20 10:13:07

像这样的东西吗?


(来源:yaroslavvb.com

这是我使用的代码。对于上面的特定任务来说可能太复杂了,它是我必须可视化整数网格的代码的一部分,例如 this< /a>

A = Sqrt[2/3] {Cos[#], Sin[#], Sqrt[1/2]} & /@ 
    Table[Pi/2 + 2 Pi/3 + 2 k Pi/3, {k, 0, 2}] // Transpose;
p2r[{x_, y_, z_}] := Most[A.{x, y, z}];
n = 10;
types = 1/n Permutations /@ IntegerPartitions[n, {3}, Range[1, n]] // 
   Flatten[#, 1] &;
points = p2r /@ types;
Needs["ComputationalGeometry`"]
Graphics[{EdgeForm[Black], FaceForm[Transparent], 
  GraphicsComplex[points, 
   Polygon /@ DelaunayTriangulation[points // N][[All, 2]]]}]

这是做什么

  1. 类型包含所有 3 个整数元组,总和为 n。这些整数位于 R^3 的二维子空间上
  2. A 是将这些 3 元组旋转到 xy 平面的线性变换
  3. Delauney 三角剖分找到连接附近点的所有三角形

Something like this?


(source: yaroslavvb.com)

This is the code I used. Perhaps too complicated for the specific task above, it's part of code I had to visualize integer lattices like this

A = Sqrt[2/3] {Cos[#], Sin[#], Sqrt[1/2]} & /@ 
    Table[Pi/2 + 2 Pi/3 + 2 k Pi/3, {k, 0, 2}] // Transpose;
p2r[{x_, y_, z_}] := Most[A.{x, y, z}];
n = 10;
types = 1/n Permutations /@ IntegerPartitions[n, {3}, Range[1, n]] // 
   Flatten[#, 1] &;
points = p2r /@ types;
Needs["ComputationalGeometry`"]
Graphics[{EdgeForm[Black], FaceForm[Transparent], 
  GraphicsComplex[points, 
   Polygon /@ DelaunayTriangulation[points // N][[All, 2]]]}]

What this does

  1. types contains all 3 tuples of integers that add up to n. Those integers lie on a 2-dimensional subspace of R^3
  2. A is a linear transformation to rotate those 3-tuples into x-y plane
  3. Delauney triangulation finds all triangles connecting nearby points
墨落成白 2024-10-20 10:13:07

这是贝利萨留方法的一种变体。

p = Table[{2 j - i, Sqrt[3] i}, {i, 0, 9}, {j, i, 9}]

Graphics[ Line @ Join[p, Riffle @@@ Partition[p, 2, 1]] ]

Here is a variation on belisarius' method.

p = Table[{2 j - i, Sqrt[3] i}, {i, 0, 9}, {j, i, 9}]

Graphics[ Line @ Join[p, Riffle @@@ Partition[p, 2, 1]] ]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文