4
$\begingroup$

I got a 3Dsolid formed by subtraction of geometries through 'RegionDifference'.

My intention now is to get the center of mass of the solid.

This is the geometry that received the subtraction:

(*Corpo Principal*)
orig = {0, 0, 0};
diam1 = 50;
r1 = diam1/2;
comp = 200;
corpoPrincipal = Cylinder[{orig, {comp, 0, 0}}, r1];

This is one of the geometries that were removed:

(*Furo*)
diam2 = 15;
r2 = diam2/2;
furo = Cylinder[{{altRasgo/2, 0, -r1}, {altRasgo/2, 0, r1}}, r2];

This is the other geometry that were removed:

(*Rasgo*)
altRasgo = 30;
largRasgo = 15;
rasgo = Cuboid[{0, -r1, -7.5}, {30, r1, 7.5}];

This was the operation to generate the solid:

reg = {corpoPrincipal, furo, rasgo};
rr = RegionDifference[RegionDifference[reg[[1]], reg[[2]]], reg[[3]]];
RegionPlot3D[rr, PlotPoints -> 100]

Now that comes my question:

gggggg

enter image description here

enter image description here

I followed the concept above to obtain the center of mass. Then I created the code below:

(*Densidade*)
ρ = 0.0079(*g/mm^3*);

(*CG*)
cgCorpoPrincipal = RegionCentroid[corpoPrincipal];
cgFuro = RegionCentroid[furo];
cgRasgo = RegionCentroid[rasgo];
RegionCentroid[corpoPrincipal];

(*Massa do Corpo Principal*)
mCorpoPrincipal = ρ*π*r1^2*comp // N;

(*Massa do Rasgo*)
mRasgo = ρ*altRasgo*largRasgo*diam1 // N;

(*Massa do Furo*)
mFuro = ρ*π*r2^2*diam1 // N;

(*CG Global*)
xCGglobal = (mCorpoPrincipal*cgCorpoPrincipal[[1]] + mRasgo*cgFuro[[1]] + mFuro*cgRasgo[[1]])/(mCorpoPrincipal + mRasgo + mFuro)
yCGglobal = (mCorpoPrincipal*cgCorpoPrincipal[[2]] + mRasgo*cgFuro[[2]] + mFuro*cgRasgo[[2]])/(mCorpoPrincipal + mRasgo + mFuro)
zCGglobal = (mCorpoPrincipal*cgCorpoPrincipal[[3]] + mRasgo*cgFuro[[3]] + mFuro*cgRasgo[[3]])/(mCorpoPrincipal + mRasgo + mFuro)

I am considering the solids in the unit Length: $mm$

And the density applied was: $0.0079 g/mm^3$

The result through my code was this:

x=93.7186 y=0. z=0.

I noticed a flaw in my conception, because I compared with the results that I have had in other software that I work very well (SolidWorks).

Through the SolidWorks software I got the following result:

x=106.59 y=0.00 z=0.00

enter image description here

I realized that I cannot take into account the total mass of each subtracted solid. I have to get a mass that corresponds with the INTERSECTION OF SOLIDS.

Watching the animation below it is easy to see what I am saying...

Finally, how can I get the correct results?

$\endgroup$

2 Answers 2

6
$\begingroup$

From my answer from your previous question.

region1 = (comp > x > 0 && y^2 + z^2 < r1^2);
region2 = (((x - altRasgo/2)^2 + y^2) < r2^2 && r1 > z > -r1);
region3 = (0 < x < 30 && -r1 < y < r1 && -7.5 < z < 7.5);
region = region1 && ! region2 && ! region3;

r = DiscretizeRegion[
  ImplicitRegion[
   region, {x, y, z}], {{0, comp}, {-comp/2, comp/2}, {-comp/2, 
    comp/2}}, Method -> "RegionPlot3D", MaxCellMeasure -> 10];

p = RegionCentroid[r]

{106.663, 0.0000254679, 0.0000169948}

Linex = {Line[{p - {150, 0, 0}, p + {150, 0, 0}}]};
Liney = {Line[{p - {0, 150, 0}, p + {0, 150, 0}}]};
Linez = {Line[{p - {0, 0, 150}, p + {0, 0, 150}}]};
rr = GraphicsComplex[MeshCoordinates@#, MeshCells[#, 2]] &@r;
r2 = Graphics3D[{EdgeForm[], Darker[Gray], rr}, Lighting -> "Neutral",
   Boxed -> False]
Show[r2, Graphics3D[{Red, Linex, Liney, Linez}], ImageSize -> Large]

enter image description here

$\endgroup$
1
  • $\begingroup$ I will give my vote to you for helping me again. Already I offered my other vote for our colleague. :) $\endgroup$
    – LCarvalho
    Sep 2, 2016 at 15:23
3
$\begingroup$

Simply res=RegionCentroid[rr]

{106.587, -9.00492*10^-9, 7.5693*10^-18}

If one does

Chop[res]

{106.587, -9.00492*10^-9, 0}

so

  1. Chop[res, 10^-8]

    {106.587, 0, 0}

  2. Round[res, 0.001]

    {106.587, 0, 0}

$\endgroup$
2
  • $\begingroup$ In its reply where I could add Chop to round the values? $\endgroup$
    – LCarvalho
    Sep 2, 2016 at 15:12
  • $\begingroup$ thank you. I offer my vote to the other colleague to balance. :) $\endgroup$
    – LCarvalho
    Sep 2, 2016 at 15:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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