This is just a centre of mass problem so you can just do
x = 1/sum(masses) * sum(mass_at_x * x)
質問
I have an irregular 2D mesh and I have a list of the values of each cell, and its corresponding x, y
coordinates (for the cell centre). I would like to find the mean position of the function.
In one dimension I do
x = numpy.array([0, 0.5, 1])
z = numpy.array([0, 1, 0])
scipy.integrate.simps(x * z, x)
but in two dimensions this isn't possible because x
and y
are not evenly spaced.
The function would return (0, 0)
for this mesh:
that has these z values:
SOLUTION:
this is just a centre of mass problem so you can just do
x = 1/sum(masses) * sum(mass_at_x * x)
解決
This is just a centre of mass problem so you can just do
x = 1/sum(masses) * sum(mass_at_x * x)