使用3D像素绘制球体(体素) [英] Draw a sphere using 3D pixels (voxels)

查看:1639
本文介绍了使用3D像素绘制球体(体素)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您能否提供一个算法,可以得出只使用基本的积在三维空间中的球(X,Y,Z)原语(这将绘制一个体素) ?

Can you suggest an algorithm that can draw a sphere in 3D space using only the basic plot(x,y,z) primitive (which would draw a single voxel)?

我希望类似布氏圈算法的东西,但对于3D而不是2D的。

I was hoping for something similar to Bresenham's circle algorithm, but for 3D instead of 2D.

通知你,我工作的一个硬件项目,是利用LED的3维矩阵低分辨率3D显示器,所以我需要实际绘制一个球体,而不仅仅是一个2D投影(即圆圈)。

FYI, I'm working on a hardware project that is a low-res 3D display using a 3-dimensional matrix of LEDs, so I need to actually draw a sphere, not just a 2D projection (i.e. circle).

该项目是非常类似:

...或者看到它在行动这里

... or see it in action here.

一种可能性我心目中是这样的:

One possibility I have in mind is this:

  • 计算极点(给定的半径)(用于集中在原点的领域,这些将是 -r 和的Y坐标 + - [R
  • 片领域:对每个水平面 P <子>我这些坐标之间,计算由相交得到的圆的半径所述平面与球=> 研究 <子>我。
  • 在画半径的实际圈子研究 <子>我的平面 P <子>我采用布氏算法。
  • calculate the Y coordinates of the poles (given the radius) (for a sphere centered in the origin, these would be -r and +r)
  • slice the sphere: for each horizontal plane pi between these coordinates, calculate the radius of the circle obtained by intersecting said plane with the sphere => ri.
  • draw the actual circle of radius ri on plane pi using Bresenham's algorithm.

FWIW,我使用的是 .NET微架构微处理器,所以编程是C#,但我并不需要答案在C#。

FWIW, I'm using a .NET micro-framework microprocessor, so programming is C#, but I don't need answers to be in C#.

推荐答案

简单,暴力的方法是遍历网格中的每一个像素,并计算出球中心的距离。然后着色体素,如果它的距离小于所述球体的半径。您可以通过消除平方根和积比较平方半径节省了大量的说明。

The simple, brute force method is to loop over every voxel in the grid and calculate its distance from the sphere center. Then color the voxel if its distance is less than the sphere radius. You can save a lot of instructions by eliminating the square root and comparing the dot product to the radius squared.

pretty的很不理想,肯定。但在如图所示的8x8x8格,你需要为每个领域做操作512次。如果球中心的网格,它的半径是一个整数,你只需要整数运算。点积3乘2加。乘以速度很慢;比方说,他们把每4条指令。另外,您需要一个比较。添加的加载和存储,让我们说这收费是每像素20的说明。这是每球10240指令。

Pretty far from optimal, sure. But on an 8x8x8 grid as shown, you'll need to do this operation 512 times per sphere. If the sphere center is on the grid, and its radius is an integer, you only need integer math. The dot product is 3 multiplies and 2 adds. Multiplies are slow; let's say they take 4 instructions each. Plus you need a comparison. Add in the loads and stores, let's say it costs 20 instructions per voxel. That's 10240 instructions per sphere.

这是Arduino的运行频率为16 MHz可能推每秒1562球。除非你在做吨的其他数学和I / O,这种算法应该是够用了。

An Arduino running at 16 MHz could push 1562 spheres per second. Unless you're doing tons of other math and I/O, this algorithm should be good enough.

这篇关于使用3D像素绘制球体(体素)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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