7
$\begingroup$

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.

$\endgroup$
15
$\begingroup$
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}

$\endgroup$
  • $\begingroup$ It seems you have included a method for everyone. xD $\endgroup$ – Mr.Wizard Jan 22 '17 at 6:39
  • $\begingroup$ @Mr.Wizard, for those interested in the last one, i wanted to give a link to the first appearance of the +##& trick, but cannot search with the keyword "+##&". Do you happen to know when you first used it on this site? $\endgroup$ – kglr Jan 22 '17 at 7:19
  • 1
    $\begingroup$ Unsure of first post, maybe on Stack Overflow, but these at least relate: (5038), (19075) (27554), (27978), (31797), (52318), (71348). I included the pattern equivalent (e.g. first link) -- I actually use that more often. $\endgroup$ – Mr.Wizard Jan 22 '17 at 7:49
3
$\begingroup$

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

$\endgroup$
2
$\begingroup$

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}

$\endgroup$
  • $\begingroup$ @Carol Woll That answer was very good. I had no idea that with lines this would be possible. $\endgroup$ – LCarvalho Jun 9 '17 at 11:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.