7

I have three masses of 3, 4, and 5, located at the points $(-1,1)$, $(2,-1)$, and $(3,2)$. To find the center of mass, I performed these steps.

pts = {{-1, 1}, {2, -1}, {3, 2}};
m = {3, 4, 8};
xbar = Total[pts[[All, 1]]*m]/Total[m]
ybar = Total[pts[[All, 2]]*m]/Total[m]

Does anyone perform this task using other Mathematica commands? I'm heading toward using the RegionCentroid command in the plane, but could not use it with this example.

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
David
  • 14,883
  • 4
  • 44
  • 117

3 Answers3

15
m.pts / Total[m]
Mean @ WeightedData[pts, m]
Normalize[m.pts, Last]
Normalize[m, Total].pts
Divide[{##}, #2] & @@ (m.pts)

all give

{29/15, 1}

So do

☺ = (#.#2)/(+## & @@ #) &;
☺[m, pts]

{29/15, 1}

and

☹ = {##}/#2 & @@ (#.#2) &;
☹[m, pts]

{29/15, 1}

kglr
  • 394,356
  • 18
  • 477
  • 896
3

To represent what you are describing I tried to simulate cylinders with equal diameters, but with different heights representing the weight.

The red cylinders are the masses distributed as the sts list is indicating.

The green cylinder represents the base point for this system, in other words, the center of gravity of the cylinder set (ptCG).

pts = {{-1, 1}, {2, -1}, {3, 2}};
m = {3, 4, 8};

ptCG = m.pts/Total[m];

mass = {Red, 
   Cylinder[{Append[pts[[#]], 0], Append[pts[[#]], m[[#]]]}, .2] & /@ 
    Range[3]};

l1 = Line[{{-1.11094004, 0.83358994, 0}, {1.88905996, -1.16641006, 
     0}}];
l2 = Line[{{-1.04850712, 1.1940285, 0}, {2.95149288, 2.1940285, 0}}];
l3 = Line[{{2.18973666, -1.06324555, 0}, {3.18973666, 1.93675445, 0}}];

CG = {Green, Cylinder[{Append[ptCG, 0], Append[ptCG, -.2]}, .2]};

Graphics3D[{mass, CG, Red, Dashed, l1, l2, l3}, Boxed -> False]

enter image description here

LCarvalho
  • 9,233
  • 4
  • 40
  • 96
2

Since the OP mentioned using RegionCentroid, here is a RegionCentroid approach:

Most@RegionCentroid@RegionUnion[
    Line[{{-1,1,0},{-1,1,3}}],
    Line[{{2,-1,0},{2,-1,4}}],
    Line[{{3,2,0},{3,2,8}}]
]

{29/15, 1}

Carl Woll
  • 130,679
  • 6
  • 243
  • 355