【问题标题】:Using tetgen or triangle (or meshpy) to create a hollow dome使用 tetgen 或三角形(或 meshpy)创建一个空心圆顶
【发布时间】:2015-03-17 22:32:54
【问题描述】:

我正在使用 tetgen 尝试创建一个空心圆顶。我正在使用三角形,然后只是对一个圆进行三角剖分并根据等式 z = sqrt(abs(r^2 - x^2 - y^2)) 提高 z 值,但我在边缘附近的拉伸非常糟糕。

所以我想只生成这个圆顶的一堆点,然后在不填充的情况下对其进行网格划分。Tetgen 基本上是通过提供 .node 和 .faces 文件来为我做这件事,但问题是我仍然触底,我不知道如何摆脱它。我对 tetgen 和 meshpy 还很陌生,所以如果有人能给我一个工作流程,我将不胜感激。答案实际上可能很简单。

例如,我可以用一个简单的函数在圆底周围创建点:

def gen_pts_on_circle(num_pts, radius):
    pnts = []
    theta = 360.0 / num_pts

    # loop through circle using theta for point placement
    for i in np.arange(0, 360, theta):
        x = radius * np.cos(np.radians(i))
        y = radius * np.sin(np.radians(i))
        z = 0.0
        pnts.append((x,y,z))
     return np.array(pnts)

然后我使用函数在圆顶上生成随机点:

def gen_random_pts(num_pts, radius): 
    pts = []
    for i in xrange(num_pts):
        q = np.random.random() * (np.pi * 2.0)
        r = np.sqrt(np.random.random())
        x = (radius * r) * np.cos(q)
        y = (radius * r) * np.sin(q) 
        # Just the sphere equation with abs value to make a dome
        z = np.sqrt(abs(r**2 - x**2 - y**2))
        pts.append((x,y,z))
    return np.array(pts)

然后我只需从 .node 文件中提取标题并运行 tetgen 即可获取 .face 文件。这种方法的唯一问题是当我需要它成为一个开放的圆顶时,底部就在那里。

我更愿意使用meshpy,但是生成这些点然后像这样将其输入meshpy不会返回任何东西......

from meshpy.tet import MeshInfo, build 

# Generating all of the points using the functions
pts_circ = gen_pts_on_circle(100, 5) 
points = np.vstack((pts_circle, gen_random_pts(500, 5)))

# Building with tet
mesh_info = MeshInfo()
mesh_info.set_points(points)
mesh = build(info)

打印 np.array(mesh.facets) 和 print np.array(mesh.points) 现在只是空数组。

有没有人知道如何在不设置所有方面的情况下使用 meshpy,或者像命令行 tetgen 那样使用这种构建方法来构建方面?这并没有真正解决我的问题,即圆顶底部没有打开,但我一直在努力解决这个问题。任何帮助将不胜感激。谢谢!

【问题讨论】:

  • 您能否提供(在您的原始帖子中)设置圆顶几何的最少代码?

标签: python mesh tetgen


【解决方案1】:

以防万一其他人正在寻找这个答案,我是从 meshpy 的创建者那里得到的。基本上你需要重写选项来摆脱默认的“pq”命令。所以

from meshpy.tet import MeshInfo, Options, build

opts = Options("") # Overriding 'pq' with no options or flags
mesh_info = MeshInfo()
mesh = build(mesh_info, options=opts)

希望这对遇到同样问题的人有所帮助。

【讨论】:

    猜你喜欢
    • 2011-04-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-20
    相关资源
    最近更新 更多