在voxels中有效绘制球体表面? [英] Draw a sphere surface in voxels efficiently?

查看:131
本文介绍了在voxels中有效绘制球体表面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大的3D网格(为了简单起见,网格框的最小尺寸为1x1x1),并且只想绘制这个网格中可变半径的大量球体的表面。然而我想消除孔和丘的典型光栅化问题。

我也不想做一个暴力方法(找到球体中心半径内的所有像素,删除非边界像素),因为我将创建数百万个这样的领域,其中一些可能具有非常高的半径。圈子的 Bresenham算法与我想要的类似,但我想知道如何适应这对于球体的形状。



任何人都可以帮忙吗?

解决方案

好吧,我想我已经解决了。不知道这是否是最有效的版本。



基本上,球体的曲面是由无限的一组半径组成的,半径r随着移动而增加然后减小通过垂直于与该圆相交的平面的轴。可以用半圆来描述半径的增减。

在离散空间中,我们可以通过绘制一组圆来有效地模拟球体的表面使用Bresenham算法,其中半径是使用额外的bresenham圆来计算的,其半径是球的半径。这个半径被认为是从圆上向上,在第三维。



其他圆形围绕着它,就好像主圆是一个框建设。



我不完全确定这是否容易理解,所以希望该算法可能会更轻一些:

  public static void bresenhamSphere(Vector3 center,int radius)
{
List< Vector3> points = new List< Vector3>();
foreach(在bresenhemCircle中的点坐标(新点(0,0),半径))//获取以原点为中心的初始bresenham圆的点集(稍后我们将添加坐标)
{
int z = coord.Y; //我认为你应该能够选择与Z匹配的哪个坐标和任意匹配的半径,但是这更直观
int r = coord.X; //新圆的半径
foreach(在bresenhemCircle中的点的位置(新点((int)(centre.X),(int)(centre.Y)),r))//得到圆的跨度围绕原始圆圈,这将使球体的表面 - 这次创建它们在参数
{
points.Add(new Vector3(point。)中提供的中心点的x和y坐标处。 X,point.Y,(int)(centre.Z)+ z)); //通过添加z值并将其添加到列表中,将2D结果转换为3D点。





$ b在哪BresenhamCircle(center,radius )返回由所提供的中心和半径形成的圆的圆周上的所有像素的坐标。

其中BresenhamSemiCircle(中心,半径)返回所有像素的坐标由中心和半径形成的半圆的圆周提供。

另外一个增强将是不添加新圈子的初始点,因为我们已经有了这些原来的圈子运行,但我不知道有多少奖金在那里。


I have a large 3D grid (with minimum grid box size of 1x1x1 for simplicity) and want to draw only the surface of a large number of spheres with variable radius in this grid. However I want to eliminate the typical rasterization problems of holes and mounds.

I also don't want to do a brute force approach (find all pixels within radius of sphere centre, remove non-boundary pixels) as I'll be creating millions of these spheres, and some of them could have very high radii. The Bresenham algorithm for circles is similar to what I want, but I'm wondering how I could adapt this to the sphere shape.

Anybody out there able to help?

解决方案

Ok I think I have it worked out. Not sure if this is the most efficient version though.

Essentially a sphere's surface is made up of an infinite set of circles with radius r that increases and then decreases as you move through the axis perpendicular to the plane intersecting that circle. The increase and decrease of the radius can be described using a semicircle.

In a discrete space we can then model the sphere's surface in an efficient manner by drawing a set of circles using the Bresenham algorithm where the radius is calculated using an additional bresenham circle, whose radius is that of the spheres. This radius is envisioned as being sticking "up" from the circle, in the third dimension.

The other circles build up around it as if the primary circle is a frame for construction.

I'm not entirely sure if that was all that easy to understand, so hopefully the algorithm might shed a bit more light:

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.
            }
        }
    }

Where BresenhamCircle(centre, radius) returns the coordinates of all pixels on the circumference of the circle formed of the centre and radius provided.

Where BresenhamSemiCircle(centre, radius) returns the coordinates of all pixels on the circumference of the semicircle formed of the centre and radius provided.

One additional enhancement would be to not add in the initial points on the new circles as we already have these from the original circle run, but I'm not sure how much of a bonus there is in that.

这篇关于在voxels中有效绘制球体表面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆