【发布时间】:2014-10-31 22:59:56
【问题描述】:
我希望能够获取一个 STL 文件(三角面网格)并用点填充网格,使点的密度保持不变。我正在用 Fortran 编写程序。
到目前为止,我可以读取二进制 STL 文件并存储顶点和表面法线。这是一个已读取的示例文件(为简单起见,为 2D 视图)。
我当前的算法使用以下公式填充每个三角形:
x = v1 + a(v2 - v1) + b(v3 - v1) (from here)
其中 v1、v2、v3 是三角形的顶点,x 是三角形内(或边上)的任意位置。 “a”和“b”在 0 和 1 之间变化,并且它们的总和小于 1。它们表示沿两条边(从同一顶点开始)的距离。每个边缘的粒子之间的间隙应该相同。以下是我得到的结果示例:
如果远不均匀,则产生的粒子密度。你知道如何调整我的代码,使密度在三角形之间保持不变吗?相关代码如下:
! Do for every triangle in the STL file
DO i = 1, nt
! The distance vector from the second point to the first
v12 = (/v(1,j+1)-v(1,j),v(2,j+1)-v(2,j),v(3,j+1)- v(3,j)/)
! The distance vector from the third point to the first
v13 = (/v(1,j+2)-v(1,j),v(2,j+2)-v(2,j),v(3,j+2)- v(3,j)/)
! The scalar distance from the second point to the first
dist_a = sqrt( v12(1)**2 + v12(2)**2 + v12(3)**2 )
! The scalar distance from the third point to the first
dist_b = sqrt( v13(1)**2 + v13(2)**2 + v13(3)**2 )
! The number of particles to be generated along the first edge vector
no_a = INT(dist_a / spacing)
! The number of particles to be generated along the second edge vector
no_b = INT(dist_b / spacing)
! For all the particles to be generated along the first edge
DO a = 1, no_a
! For all the particles to be generated along the second edge
DO b = 1, no_b
IF ((REAL(a)/no_a)+(REAL(b)/no_b)>1) EXIT
temp(1) = v(1,j) + (REAL(a)/no_a)*v12(1) + (REAL(b)/no_b)*v13(1)
temp(2) = v(2,j) + (REAL(a)/no_a)*v12(2) + (REAL(b)/no_b)*v13(2)
temp(3) = v(3,j) + (REAL(a)/no_a)*v12(3) + (REAL(b)/no_b)*v13(3)
k = k + 1
s_points(k, 1:3) = (/temp(1), temp(2), temp(3)/)
END DO
END DO
j = j + 3
END DO
【问题讨论】:
-
人们似乎对过去几天的反对票真的太敏感了,尽管其中一些已经到位。你能尝试改变间距,使单位盒子的面积(体积)保持不变吗?溶液不会是各向同性的,但密度应该是恒定的。
-
我很困惑为什么我被否决了,评论会很有用,所以我可以编辑我的问题以使其更有用/更清晰。我认为实现各向同性会很棘手。我会按照您的建议尝试并计算出每个平面/三角形的体积。从那我会尝试并确保每个区域的粒子数是恒定的。
-
尝试缩放间距,以便由向量 v12/spacing 和 v13/spacing 组成的四边形具有定义的区域。顺便提一句。在 Fortran 2008 中有一个函数
norm2可用于轻松计算向量的长度。
标签: fortran computational-geometry particles