2012-03-13 76 views
1

我有一個很大的3D網格(爲了簡單起見,網格框的最小尺寸爲1x1x1),並且只希望在這個網格中繪製大量可變半徑球體的表面。不過,我想消除洞和丘的典型光柵化問題。有效地繪製體素中的球體表面?

我也不想做一個暴力方法(找到球體中心半徑內的所有像素,刪除非邊界像素),因爲我將創建數百萬個這樣的球體,其中一些可能會有高半徑。圈子的Bresenham algorithm類似於我想要的,但我想知道如何將其適應球形。

有人能幫忙嗎?

+0

相似:http://stackoverflow.com/questions/9084189/draw-a-sphere-using-3d-pixels-voxels http://stackoverflow.com/questions/564492/recommend-some-bresenhams-like-算法的球面映射在2d – AakashM 2012-03-13 13:38:23

+0

啊感謝您找到這個。我自己也遇到了第一個鏈接,但假設他們正在尋找一個填充球體,因爲迴應僅涵蓋了我上面概述的蠻力方法(或者除非我能計算體素的確切跨度,否則對我無用的跨度方法轉換角度變化 – 2012-03-13 14:31:56

回答

2

好吧,我想我已經解決了。不知道這是否是最有效的版本。

本質上,一個球體的表面由一組半徑爲r的無限圓組成,當您通過垂直於與該圓相交的平面的軸移動時,該半徑增加,然後減小。半徑的增減可以用半圓來描述。

在一個離散空間中,我們可以通過使用Bresenham算法繪製一組圓,以高效的方式對球體表面進行建模,其中半徑是使用額外的bresenham圓來計算的,其半徑是球的半徑。這個半徑被設想爲在第三維上從圓上「向上」粘着。

其他的圈子圍繞它建立起來,好像主要的圈子是一個建築框架一樣。

我不能完全肯定,如果這是那麼容易理解,所以希望算法可能擺脫多一點光:

public static void bresenhamSphere(Vector3 centre, int radius) 
    { 
     List<Vector3> points = new List<Vector3>(); 
     foreach (Point coord in bresenhemCircle(new Point(0,0), radius)) //get the set of points for an initial bresenham circle centred at the origin (we'll add the coordinates later) 
     { 
      int z = coord.Y; //I think you should be able to pick which coord matches to Z and which matches to radius arbitrarily, but this was more intuitive 
      int r = coord.X; //the radius for the new circles 
      foreach(Point point in bresenhemCircle(new Point((int)(centre.X),(int)(centre.Y)), r)) //get the circle spans around the original circle, this will make the surface of the sphere - this time create them at the x and y coordinates of the centre point supplied in the parameters 
      { 
       points.Add(new Vector3(point.X, point.Y, (int)(centre.Z) + z)); //convert the 2D results into 3D points by adding in the z value and add to the list. 
      } 
     } 
    } 

凡BresenhamCircle(圓心,半徑)返回所有像素的座標在由所提供的中心和半徑形成的圓的圓周上。

其中BresenhamSemiCircle(中心,半徑)返回由所提供的中心和半徑形成的半圓的圓周上的所有像素的座標。

一個額外的增強將是不添加在新的圈子的初始點,因爲我們已經從原來的圈子運行這些,但我不知道這是多少獎金。

+0

原則上看起來不錯(自己還沒有嘗試過)。有趣的是,谷歌搜索'sphere rasterize'**不會引起任何有趣的事情......我的一部分人確信*在Bresenham的Line + Circle中使用的技術*必須可擴展到表面,但我找不到任何人完成它! – AakashM 2012-03-13 16:33:41

+1

我認爲如果將圓算法擴展爲包含初始誤差或半徑分數,這將工作得非常好。我認爲最終會出現一個問題,即在一個球體的赤道附近將其劃分爲一個圓柱體,因爲您多次繪製相同的圓,實際上,即使x = 0或y,通過圓弧應該略有變化= 0分s會保持不變。我認爲當你沿着第一個圓圈(半徑)時,使用每個點的累積誤差作爲第二個圓圈的輸入可以解決這個問題。 – rjp 2013-12-04 18:31:28