2014-10-28 102 views
0

我希望能夠採用STL文件(三角網格表面網格)並用點填充網格,使點的密度保持不變。我正在用Fortran編寫程序。使用點填充STL表面網格

到目前爲止,我可以讀取二進制STL文件並存儲頂點和曲面法線。這裏是一個已被讀入的示例文件(爲了簡單起見,2D視圖)。 - + B(V3 - V1)(from here)

當V1,V2

X = V1 + A(V1 V2):

Example STL file in 2 dimensions.

我的當前算法使用下面的公式填充每個三角,v3是三角形的頂點,x是三角形內(或邊緣)的任意位置。 「a」和「b」在0和1之間變化,它們的和小於1.它們表示沿着兩條邊的距離(從同一個頂點開始)。粒子之間的差距應該是相同的每個邊緣。下面是我得到的結果的一個例子: Example STL file in 2 dimensions populated with points

由此產生的粒子密度如果遠遠不均勻。你有什麼想法,我可以如何調整我的代碼,使密度從三角形到三角形不變?下面的相關代碼:

 ! 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 
+1

人們似乎在最後幾天的downvotes真的過於敏感,雖然他們中的一些已經到位。您是否可以嘗試更改間距以使單位框的面積(體積)保持不變?該解決方案不會是各向同性的,但密度應該是恆定的。 – 2014-10-28 21:05:04

+0

我很困惑,爲什麼我被淹沒了,一個評論會很有用,所以我可以編輯我的問題,使其更有用/清晰。 我認爲這將是棘手的,以實現各向同性。我試試你的建議,並計算每個飛機/三角形的體積。從這種情況下,請儘量確保每個區域的顆粒數量不變。 – 1QuickQuestion 2014-10-29 10:17:27

+1

嘗試縮放間距,以便從矢量v12 /間距和v13 /間距構成的四邊形具有定義的區域。順便說一句。在Fortran 2008中有一個函數'norm2',可以用來輕鬆計算矢量的長度。 – 2014-10-29 10:22:56

回答

0

我去的解決方案是將每個三角形分成兩個直角三角形。這是通過將垂直於最長邊緣的最長邊緣的vetex投影到最長邊緣上來完成的。這將三角形分成兩個更小的三角形,每個角度都爲90度。關於如何做到這一點的詳細答案可以找到here。通過沿着兩個90°彎曲產生點,可以實現粒子的均勻分佈。

該方法需要進行調整,以便粒子不會沿着多個三角形共有的邊緣生成一次以上。我還沒有這樣做。請參閱下圖以獲取結果。這種解決方案不能實現各向同性的分佈,但這不是我想要的應用所關心的問題。 (感謝Vladimir F對norm2的評論和建議,我試圖實現他的方法,但沒有足夠的能力使其工作)。

enter image description here