.NET

Reply
Distinguished Contributor
116 Posts
1 Kudo
Registered: ‎02-26-2009
Post 1 of 5

MassProperties.Centroid is Incorrect

182 Views, 4 Replies
07-19-2012 11:52 AM

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

*Expert Elite*
1,569 Posts
171 Kudos
Registered: ‎10-08-2008
Post 2 of 5

Re: MassProperties.Centroid is Incorrect

07-19-2012 12:01 PM in reply to: junoj

Have you tried:

 

MsgBox(string.Format("{0:f6};{1:f6}[2:f6}",cg.X, cg.Y, cg.Z))

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Distinguished Contributor
116 Posts
1 Kudo
Registered: ‎02-26-2009
Post 3 of 5

Re: MassProperties.Centroid is Incorrect

07-19-2012 12:17 PM in reply to: Hallex

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.

 

 

*Expert Elite*
2,142 Posts
255 Kudos
Registered: ‎04-29-2006
Post 4 of 5

Re : MassProperties.Centroid is Incorrect

07-19-2012 12:35 PM in reply to: junoj

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')


Gilles Chanteau
Distinguished Contributor
116 Posts
1 Kudo
Registered: ‎02-26-2009
Post 5 of 5

Re : MassProperties.Centroid is Incorrect

07-19-2012 01:08 PM in reply to: _gile

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

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are you interested in helping shape the future of the Autodesk Community? To participate in this brief usability study, please click here. Your time and input is greatly appreciated!