好吧,我想我已经解决了。但不确定这是否是最有效的版本。
本质上,球体的表面由一组无限的半径为 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.
}
}
}
其中 Bresenham Circle(center, radius) 返回由提供的圆心和半径形成的圆的圆周上所有像素的坐标。
其中 Bresenham Semi Circle(center, radius) 返回由提供的中心和半径形成的半圆圆周上所有像素的坐标。
一项额外的增强功能是不添加新圆圈上的初始点,因为我们已经从原始圆圈运行中获得了这些初始点,但我不确定其中有多少好处。