.NET

Reply
Distinguished Contributor
Posts: 113
Registered: ‎02-26-2009
Message 1 of 5 (146 Views)

MassProperties.Centroid is Incorrect

146 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,557
Registered: ‎10-08-2008
Message 2 of 5 (144 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
Posts: 113
Registered: ‎02-26-2009
Message 3 of 5 (141 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*
Posts: 1,982
Registered: ‎04-29-2006
Message 4 of 5 (136 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
Posts: 113
Registered: ‎02-26-2009
Message 5 of 5 (128 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

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Welcome to the new Autodesk Community!
If this is your first visit, click here to get started and make the most of the Community. Let us know what you think of the new experience in the Community Feedback Forum.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community