如何计算多面体的质量和转动惯量?
为了在刚体模拟中使用,我想计算质量和惯性张量(惯性矩),给定一个表示(不一定是凸)对象边界的三角形网格,并假设内部密度恒定。
For use in a rigid body simulation, I want to compute the mass and inertia tensor (moment of inertia), given a triangle mesh representing the boundary of the (not necessarily convex) object, and assuming constant density in the interior.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
假设你的修剪网格是闭合(无论是否凸),有办法!
正如 dmckee 指出的那样,一般方法是从每个表面三角形构建四面体,然后应用明显的数学来合计每个四面体的质量和力矩贡献。 当身体表面有凹处时,无论从哪个参考点看,这些凹处都会形成内部口袋,这就出现了窍门。
因此,首先,选择一些参考点(模型坐标中的原点就可以了),它甚至不需要位于身体内部。 对于每个三角形,将该三角形的三个点连接到参考点以形成四面体。 技巧如下:使用三角形的表面法线来确定三角形是面向还是远离参考点(您可以通过查看法线与指向 的向量的点积的符号来找到该点)三角形的质心)。 如果三角形背向参考点,则正常处理其质量和力矩,但如果它面向参考点(表明参考点和实体之间存在开放空间),则否定该四面体的结果。
实际上,它的作用是过度计算体积块,然后在这些区域被证明不是实体的一部分时进行纠正。 如果一个物体有很多润滑的凸缘和怪诞的褶皱(看到那个图像了吗?),特定的体积可能会被高估很多,但如果你的网格是,它会被减去足够的次数来抵消它。关闭。 通过这种方式,您甚至可以处理对象中的内部空间气泡(假设法线设置正确)。 最重要的是,每个三角形都可以独立处理,因此您可以随意并行化。 享受!
事后思考:您可能想知道当点积给出的值为零或接近零时会发生什么。 仅当三角形面平行(其法线垂直)且方向指向参考点时,才会发生这种情况 - 无论如何,这只发生在面积较小或为零的退化四面体上。 也就是说,只有当 tet 无论如何都不会做出任何贡献时,增加或减少 tet 的贡献的决定才值得怀疑。
Assuming your trimesh is closed (whether convex or not) there is a way!
As dmckee points out, the general approach is building tetrahedrons from each surface triangle, then applying the obvious math to total up the mass and moment contributions from each tet. The trick comes in when the surface of the body has concavities that make internal pockets when viewed from whatever your reference point is.
So, to get started, pick some reference point (the origin in model coordinates will work fine), it doesn't even need to be inside of the body. For every triangle, connect the three points of that triangle to the reference point to form a tetrahedron. Here's the trick: use the triangle's surface normal to figure out if the triangle is facing towards or away from the reference point (which you can find by looking at the sign of the dot product of the normal and a vector pointing at the centroid of the triangle). If the triangle is facing away from the reference point, treat its mass and moment normally, but if it is facing towards the reference point (suggesting that there is open space between the reference point and the solid body), negate your results for that tet.
Effectively what this does is over-count chunks of volume and then correct once those areas are shown to be not part of the solid body. If a body has lots of blubbery flanges and grotesque folds (got that image?), a particular piece of volume may be over-counted by a hefty factor, but it will be subtracted off just enough times to cancel it out if your mesh is closed. Working this way you can even handle internal bubbles of space in your objects (assuming the normals are set correctly). On top of that, each triangle can be handled independently so you can parallelize at will. Enjoy!
Afterthought: You might wonder what happens when that dot product gives you a value at or near zero. This only happens when the triangle face is parallel (its normal is perpendicular) do the direction to the reference point -- which only happens for degenerate tets with small or zero area anyway. That is to say, the decision to add or subtract a tet's contribution is only questionable when the tet wasn't going to contribute anything anyway.
将对象分解为围绕选定内部点的一组四面体。 (这是使用每个三角形面元素和所选中心的实体。)
您应该能够查找每个元素的体积。 转动惯量也应该可用。
如果表面是非凸的,那就会更麻烦。
我似乎记错了命名法,而且倾斜不是我想要的形容词。 我的意思是不定期。
Decompose your object into a set of tetrahedrons around the selected interior point. (That is solids using each triangular face element and the chosen center.)
You should be able to look up the volume of each element. The moment of inertia should also be available.
It gets to be rather more trouble if the surface is non-convex.
I seem to have miss-remembered by nomenclature and skew is not the adjective I wanted. I mean non-regular.
D. Eberly 所著的《游戏物理,第二版》一书对此进行了介绍。 第 2.5.5 章和示例代码可在线获取。 (刚刚找到它,还没有尝试过。)
另请注意,多面体不必是凸的,公式才能起作用,它只需 简单。
This is covered in the book "Game Physics, Second Edition" by D. Eberly. The chapter 2.5.5 and sample code is available online. (Just found it, haven't tried it out yet.)
Also note that the polyhedron doesn't have to be convex for the formulas to work, it just has to be simple.
我会看一下 vtkMassProperties。 这是一个给定一个包围体积的表面,用于计算此值的相当强大的算法。
I'd take a look at vtkMassProperties. This is a fairly robust algorithm for computing this, given a surface enclosing a volume.
如果您的多面体很复杂,请考虑使用蒙特卡罗积分,它通常用于多维积分。 您将需要一个封闭的超立方体,并且需要能够测试给定点是在多面体内部还是外部。 您需要耐心等待,因为蒙特卡罗集成速度很慢。
像往常一样从维基百科开始,然后按照外部链接页面进行进一步阅读。
(对于那些不熟悉蒙特卡洛积分的人,以下是如何计算质量。在包含的超立方体中选取一个点。添加到
point_total
计数器。它在多面体中吗?如果是,添加到 < code>point_internal 计数器。执行此操作(请参阅收敛和误差界限估计。)然后mass_polyhedron/mass_hypercube \approxpoints_internal/points_total
对于惯性矩,您可以对每个计数进行加权。点到参考轴的距离的平方。
棘手的部分是测试一个点是在多面体内部还是外部。我确信有计算几何算法可以解决这个问题。
If your polydedron is complicated, consider using Monte Carlo integration, which is often used for multidimensional integrals. You will need an enclosing hypercube, and you will need to be able to test whether a given point is inside or outside the polyhedron. And you will need to be patient, as Monte Carlo integration is slow.
Start as usual at Wikipedia, and then follow the external links pages for further reading.
(For those unfamiliar with Monte Carlo integration, here's how to compute a mass. Pick a point in the containing hypercube. Add to the
point_total
counter. Is it in the polyhedron? If yes, add to thepoint_internal
counter. Do this lots (see the convergence and error bound estimates.) Thenmass_polyhedron/mass_hypercube \approx points_internal/points_total
.For a moment of inertia, you weight each count by the square of the distance of the point to the reference axis.
The tricky part is testing whether a point is inside or outside your polyhedron. I'm sure that there are computational geometry algorithms for that.