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:
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
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?