计算凹二维多边形相对于其原点的惯性矩
我想计算(2D)凹多边形的转动惯量。我在互联网上找到了这个。但我不太确定如何解释公式...
公式 http://img101.imageshack.us/img101/8141/92175941c14cadeeb956d8f.gif
1) 这个公式正确吗?
2)如果是这样,我到 C++ 的转换是否正确?
float sum (0);
for (int i = 0; i < N; i++) // N = number of vertices
{
int j = (i + 1) % N;
sum += (p[j].y - p[i].y) * (p[j].x + p[i].x) * (pow(p[j].x, 2) + pow(p[i].x, 2)) - (p[j].x - p[i].x) * (p[j].y + p[i].y) * (pow(p[j].y, 2) + pow(p[i].y, 2));
}
float inertia = (1.f / 12.f * sum) * density;
马丁
I want to compute the moment of inertia of a (2D) concave polygon. I found this on the internet. But I'm not very sure how to interpret the formula...
Formula http://img101.imageshack.us/img101/8141/92175941c14cadeeb956d8f.gif
1) Is this formula correct?
2) If so, is my convertion to C++ correct?
float sum (0);
for (int i = 0; i < N; i++) // N = number of vertices
{
int j = (i + 1) % N;
sum += (p[j].y - p[i].y) * (p[j].x + p[i].x) * (pow(p[j].x, 2) + pow(p[i].x, 2)) - (p[j].x - p[i].x) * (p[j].y + p[i].y) * (pow(p[j].y, 2) + pow(p[i].y, 2));
}
float inertia = (1.f / 12.f * sum) * density;
Martijn
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我认为除了将公式转换为代码之外,您还有更多工作要做。您需要准确理解这个公式的含义。
当您有一个 2D 多边形时,您可以相对于给定坐标系计算三个惯性矩:关于 x 的力矩、关于 y 的力矩和极惯性矩。平行轴定理允许您从一个坐标系转换到另一个坐标系。
你知道这个公式适用于哪个力矩和坐标系吗?
下面是一些可能对您有帮助的代码,以及证明其有效的 JUnit 测试:
这是随附的 JUnit 测试:
I think you have more work to do that merely translating formulas into code. You need to understand exactly what this formula means.
When you have a 2D polygon, you have three moments of inertia you can calculate relative to a given coordinate system: moment about x, moment about y, and polar moment of inertia. There's a parallel axis theorem that allows you to translate from one coordinate system to another.
Do you know precisely which moment and coordinate system this formula applies to?
Here's some code that might help you, along with a JUnit test to prove that it works:
Here's the JUnit test to accompany it:
作为参考,这里有一个可变的 2D
org.gcs.kinetic.Vector< /code>
实现和更通用、不可变的
org.jscience.mathematics.vector
实现。本文介绍计算 2D 向量的叉积也很有帮助。For reference, here's a mutable 2D
org.gcs.kinetic.Vector
implementation and a more versatile, immutableorg.jscience.mathematics.vector
implementation. This article on Calculating a 2D Vector’s Cross Product is helpful, too.我用曲面细分做到了。并将 MOI 全部放在一起。
I did it with Tesselation. And take the MOI's all together.
编辑:很多小的数学变化
Edit: Lots of small math changes