如何计算3D重心? [英] How do I calculate a 3D centroid?

查看:363
本文介绍了如何计算3D重心?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

甚至还有3D重心之类的东西吗?让我非常清楚-在过去的两天里,我在该网站和整个网络上都在阅读和阅读有关质心的信息,因此,我非常了解该主题上的现有帖子,包括

Is there even such a thing as a 3D centroid? Let me be perfectly clear—I've been reading and reading about centroids for the last 2 days both on this site and across the web, so I'm perfectly aware at the existing posts on the topic, including Wikipedia.

也就是说,让我解释一下我要做什么.基本上,我想选择边缘和/或顶点,但不要选择面.然后,我要在3D重心位置放置一个对象.

That said, let me explain what I'm trying to do. Basically, I want to take a selection of edges and/or vertices, but NOT faces. Then, I want to place an object at the 3D centroid position.

我会告诉你我不想要的东西

I'll tell you what I don't want:

  • 顶点平均,它将在具有更高细节的网格的任何方向上拉得太远.
  • 边界框中心,因为在这种情况下我已经可以使用某些东西.

我愿意接受有关质心的建议,但是我看不到它是如何工作的,因为仅顶点或边并不能定义任何种类的质量,尤其是当我仅选择了边环时.

I'm open to suggestions about center of mass, but I don't see how this would work, because vertices or edges alone don't define any sort of mass, especially when I just have an edge loop selected.

关于踢球,我将向您展示一些我使用的 PyMEL @Emile的代码,但我认为它正在按应有的方式工作:

For kicks, I'll show you some PyMEL that I worked up, using @Emile's code as reference, but I don't think it's working the way it should:

from pymel.core import ls, spaceLocator
from pymel.core.datatypes import Vector
from pymel.core.nodetypes import NurbsCurve

def get_centroid(node):
    if not isinstance(node, NurbsCurve):
        raise TypeError("Requires NurbsCurve.")
    centroid = Vector(0, 0, 0)
    signed_area = 0.0
    cvs = node.getCVs(space='world')
    v0 = cvs[len(cvs) - 1]
    for i, cv in enumerate(cvs[:-1]):
        v1 = cv
        a = v0.x * v1.y - v1.x * v0.y
        signed_area += a
        centroid += sum([v0, v1]) * a
        v0 = v1
    signed_area *= 0.5
    centroid /= 6 * signed_area
    return centroid

texas = ls(selection=True)[0]
centroid = get_centroid(texas)
print(centroid)
spaceLocator(position=centroid)

推荐答案

理论上centroid = SUM(pos*volume)/SUM(volume)当您将零件分为有限体积时,每个体积的位置为pos,体积值为volume.

In theory centroid = SUM(pos*volume)/SUM(volume) when you split the part into finite volumes each with a location pos and volume value volume.

这正是为找到复合零件的重心而进行的计算.

This is precisely the calculation done for finding the center of gravity of a composite part.

这篇关于如何计算3D重心?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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