I have tried just about everything and the mass properties center point of gravity is coming out incorrect. Any advice would be much appreciated.
I have created a box 300x300x300 with the center of the box at 0,0,0 (for testing the cg) . The result I get is not 0,0,0 one of the values always comes out to be not zero, depending on the orientation of the box. Is this a bug?
Dim cg As Point3d = T.MassProperties.Centroid MsgBox(cg.X & vbCr & cg.Y & vbCr & cg.Z)
Thank you,
-Jay
Have you tried:
MsgBox(string.Format("{0:f6};{1:f6}[2:f6}",cg.X, cg.Y, cg.Z))
~'J'~
Hi and thank you Hallex,
The problem is not in the msgbox. The problem is that the MassProperties-Centroid is not giving the centroid.
For instance if I create a box 300,300,300 and place the center of the box at 0,0,0 when I run my code I get:
X = 0
Y = -1.07610739413994E-14
Z = 0
The X,Y,Z should be all equal to zero, but that's not the case.
Hi,
X = 0
Y = -1.07610739413994E-14
Z = 0
means:
X = 0
Y = -0.00000000000000107610739413994
Z = 0
Which is quite close to: 0, 0, 0
This is not inherent to the API nor to autoCAD, this little lack of accuracy is due to the double-precision floating-point format used to encode real numbers.
See here:
http://en.wikipedia.org/wiki/Double-precision_floating-point_format
Note:
Point3d pt = new Point3d(0.0, -1.07610739413994E-14, 0.0); pt.IsEqualTo(Point3d.Origin);
returns true (IsEqualTo() uses the 'global tolerance')
Very interesting. I have a very large file with thousands of solid pieces, is there a way to obtain the CG of all pieces or will I have to run each piece and add up all the CGs. I would like to run a quick test on a large file to see if the output is the same as the Mass Prop output
Thank you everyone for helping me.
-j