.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MassProperties.Centroid is Incorrect

4 REPLIES 4
Reply
Message 1 of 5
junoj
535 Views, 4 Replies

MassProperties.Centroid is Incorrect

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

4 REPLIES 4
Message 2 of 5
Hallex
in reply to: junoj

Have you tried:

 

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

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 3 of 5
junoj
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.

 

 

Message 4 of 5
_gile
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
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 5 of 5
junoj
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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost