.NET

Reply
Distinguished Contributor
junoj
Posts: 116
Registered: ‎02-26-2009
Message 1 of 5 (177 Views)

MassProperties.Centroid is Incorrect

177 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*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 2 of 5 (175 Views)

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
junoj
Posts: 116
Registered: ‎02-26-2009
Message 3 of 5 (172 Views)

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*
_gile
Posts: 2,114
Registered: ‎04-29-2006
Message 4 of 5 (167 Views)

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
junoj
Posts: 116
Registered: ‎02-26-2009
Message 5 of 5 (159 Views)

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 Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!