如何计算非均匀球体的质量?
我想根据三维离散不均匀密度分布计算球体的质量。假设一组不同密度的 3x3x3 立方体内接于一个球体。使用 Python 求和分区质量的最快方法是什么?
我尝试使用 scipy.integrate.dblquad 计算球体数学方程下的体积: x^2 +y^2 +z^2 = R^2 对于其中一个立方体的范围。 然而,只有当边界小于球体的半径时,结果才有效,并且假设 50,000 个球体(每个球体有 27 个立方体)的重复计算会非常慢。
另一方面,在我看来,由于质量分布相当粗糙和离散,因此无法使用 CoM 计算的常用方程。
I want to calculated the mass of a sphere based on a three-dimensional discrete inhomogeneous density distribution. Lets say a set of 3x3x3 cubes of different densities is inscribed by a sphere. What is the fastest way to sum up the partitioned masses using Python?
I tried to calculate the volume under the mathematical equation for a sphere: x^2 +y^2 +z^2 = R^2 for the range of one of the cubes using scipy.integrate.dblquad.
However, the result is only valid if the boundaries are smaller than the radius of the sphere and repetitive calculation for let's say 50,000 spheres with 27 cubes each would be quite slow.
On the other hand, the usual equation for CoM calculations couldn't be used in my opinion, due to the rather coarse and discrete mass distribution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
时序实验
您没有指定时序约束,因此我使用一个很好的集成包做了一个小实验。
如果不进行优化,如果立方体密度是简单函数,则可以在标准笔记本电脑中在 0.005 秒内计算出球坐标中的每个积分。
作为参考,这是 Mathematica 中的程序:
结果是52 秒进行 10^4 次迭代。
所以也许您不需要优化太多......
Timing Experiment
You didn't specify your timing constraints, so I've done a little experiment with a nice integration package.
Without optimization, each integral in spherical coordinates can be evaluated in 0.005 secs in a standard laptop if the cubes densities are straightforward functions.
Just as a reference, this is the program in Mathematica:
The result is 52 secs for 10^4 iterations.
So perhaps you don't need to optimize a lot ...
我无法理解你所说的“被球体内切”的确切含义。我还没有尝试过 scipy.integrate。不过,这里有一些:
将 3x3x3 立方体设置为单位密度。然后分别对每个立方体进行积分,因此这里应该有体积立方体
V_ijk
。现在,对于每个球体,您可以通过对V_ijk*D_ijk
求和来获得每个球体的质量,其中D_ijk
是球体的密度。它应该快得多,因为您现在不需要进行集成。
I cannot get your exact meaning of inscribed by a sphere. Also I havent tried the scipy.integrate. However, here are some though:
Set a 3x3x3 cube to unit density. Then take the integration for each cube respectively, so you should have the volume cube
V_ijk
here. Now for each of sphere, you can get the mass of each sphere by summingV_ijk*D_ijk
, where theD_ijk
is the density of the sphere.It should be much faster because you do not need to do integration now.
您可以获得立方体(或长方体)和球体之间相交体积的解析公式。这并不容易,但应该是可能的。我已经对二维的任意三角形和圆进行了此操作。基本思想是将交集分解为更简单的部分,例如四面体和体积球面三角形扇形,相对简单的体积公式是已知的。主要的困难在于考虑所有可能的交叉情况。幸运的是,这两个对象都是凸的,因此可以保证有一个凸的相交体积。
一种近似方法可能是简单地细分立方体,直到近似数值积分算法起作用为止;这应该还是比较快的。你知道皮克定理吗?这仅适用于 2D,但我相信,3D 概括。
You can obtain an analytic formula for the intersecting volume between a cube (or rectangular prism) and a sphere. It won't be easy, but it should be possible. I have done it for an arbitrary triangle and circle in 2D. The basic idea is to decompose the intersection into simpler pieces, like tetrahedra and volumetric spherical triangle sectors, for which relatively simple volume formulas are known. The main difficult is in considering all the possible cases of intersections. Luckily both objects are convex, so you are guaranteed a single convex intersection volume.
An approximate method might be to simply subdivide the cubes until your approximate numerical integration algorithm does work; this should still be relatively fast. Do you know about Pick's Theorem? That only works in 2D, but there are, I believe, 3D generalizations.