简体   繁体   English

找到具有加权顶点的多边形的质心

[英]Find the centroid of a polygon with weighted vertices

I know how to find the centroid (center of mass) of a regular polygon. 我知道如何找到正多边形的质心(质心)。 This assumes that every part of the polygon weighs the same. 这假设多边形的每个部分都重量相同。 But how do I calculate the centroid of a weightless polygon (made from aerogel perhaps :), where each vertex has a weight? 但是我如何计算失重多边形的质心(也许是由气凝胶制成:),每个顶点都有一个重量?

Simplified illustration of what I mean using straight line: 我用直线简化说明:

5kg-----------------5kg
           ^center of gravity

10kg---------------5kg
        ^center of gravity offset du to weight of vertices

Of course, I know how to calculate the center of gravity on a straight line with weighted vertices, but how do I do it on a polygon with weighted vertices? 当然,我知道如何计算带有加权顶点的直线上的重心,但是如何在带有加权顶点的多边形上进行计算呢?

Thanks for your time! 谢谢你的时间!

You want take a weighted average over all the vertices. 您想要对所有顶点进行加权平均。 So say your vertices are v1, v2, v3 .... vn with masses m1, m2 ...mn and have x and y coordinates v1x, v1y, v2x, v2y etc then to get the center of mass (cx, cy) you want: 所以说你的顶点是v1,v2,v3 .... vn,质量为m1,m2 ... mn,并且有x和y坐标v1x,v1y,v2x,v2y等然后得到质心(cx,cy)你要:

cx = (v1x*m1 + v2x*m2 + ... vnx*mn) / (m1 + m2 .... mn) 
cy = (v1y*m1 + v2y*m2 + ... vny*mn) / (m1 + m2 .... mn)

It's essentially the same principle as when you do it for a line. 它基本上与你为一条线做的原理相同。

1) Generate a vector for each vertex 1)为每个顶点生成一个向量

2) Multiply each vector for the weight of the vertex 2)将每个向量乘以顶点的权重

3) Sum the vectors 3)求和向量

4) Divide for total mass 4)除以总质量

5) There's your center of mass! 5)这是你的中心!

The formula would be: 公式是:

Mc = ( sum_from_0_to_max(vertices)( m_i * P_i ) / M )

where Mc is the center of the masses, m_i is the mass of vertex i , P_i the position and M the overall mass. 其中Mc是质量的中心, m_i是顶点i的质量, P_i是位置, M是整体质量。

Try to google for "rigid bodies", I guess you will find a lot helpfull information. 尝试谷歌“僵尸”,我想你会发现很多有用的信息。

Edit: 编辑:

In code it would be something like this: 在代码中它将是这样的:

   Vector3D result; // initialized with 0, 0, 0  
   Vector3D temp; // sum  
   long sumMasses = 0;  
   for( Vertex v : vertices ) {  
      temp += (v.mass * v.position);  
      sumMasses+=v.mass;  
   }  
   result = temp / sumMasses;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM