Translate Page

Main Menu

[as] Related Posts

Links & Ads

[as] Recent Posts

[as] on Twitter

Centroid and Area Properties Plugin for SketchUp

Description

A little while ago, I had a need for calculating centroids for planar shapes. To be more exact, my students had the need since I gave them an assignment that required this. Not knowing of a plugin for SketchUp that would accomplish this feat, they did it in Rhino or AutoCAD instead.

To rid SketchUp of this shortcoming, I decided to re-use some old Pascal code of mine and try my hand at writing a plugin for this. Here is now the result.

This plugin will calculate area properties for planar shapes. These shapes must be drawn on the X-Y plane (the ground plane) in SketchUp. Of course these shapes must be closed so that a single face is generated by SketchUp.

To calculate area properties, select one or more of these shapes and either choose “Get Face Centroid” from the Tools menu or the right-click context menu. The plugin will then calculate area properties for each face successively. These (area and moments Ix, Iy, Ixy) will then be displayed in a dialog that allows for copying of values. As final step, a construction point and a set of X-Y axes will be drawn at the area centroid. See the image below for details:

Screenshot of GetCentroid.rb SketchUp Plugin

Screenshot of GetCentroid.rb SketchUp Plugin

There are other plugins available that use a similar concept and draw a centerpoint. This is usually done for the center of the bounding box, which only in the case of a rectangle coincides with the area centroid. One example is the CenterPoint plugin available on Smustard.

Please note also that the accuracy of the calculations is dependent on the accuracy of the polygonal shape. While SketchUp draws lines accurately, curves are always approximated by a polyline.

PLEASE NOTE (9/20/2009): I have just noticed a potential bug when the area to be evaluated contains internal “holes” (openings). I will investigate and provide a fix soon. Until then, double-check your results in these cases.

Downloads

GetCentroid for SketchUp v.1.0 (6.5 KB, downloaded 5103 times) - PLEASE NOTE: Right-click on the link and download this Ruby (.rb ending) file. Then drop it into the SketchUp plugin directory (usually at C:\Program Files\Google\SketchUp\Plugins\ in Windows). Then re-start SketchUp and look for the new menu item in the Tools menu.

GetCentroid for SketchUp v.1.0 (RBZ version) (2.33 kB, downloaded 214 times) - PLEASE NOTE: Download the RBZ file. Then open SketchUp (v.8 M2 and above) and go to the Preferences dialog. On the Extensions tab, select "Install Extension..." and browse to the file.

Screenshots

These are some verification screenshots. The first image shows simply a rectangle and a triangle and a geometric centroid determination.

Linear shapes - verify geometrically

Linear bounded shapes

The following shape is a quarter of a circle with a radius of 2 ft and an arc made of 24 segments. If the border were a perfect arc, then the area should result to Pi (3.1416 etc.) ft^2 but SketchUp as well as this plugin calculate it as 3.1394 ft^2. This is due to SketchUp approximating all curved edges as polylines.

Precision verification

Precision verification

The image below shows a shape made with the Uniform B-Spline plugin.

Nonlinear shape boundaries

Nonlinear shape boundaries

Revision History

  • 1.0 (10/11/2008) – First version

To-Do

  • Let plugin use file’s unit system (currently it spits out only feet)
  • Add some more parameters: radius of gyration etc.
  • Calculate parameters for non-attached shapes

References

Wendehorst, Bautechnische Zahlentafeln (1998). B.G. Teubner, Stuttgart. 28. Auflage.

  • http://alexschreyer.net Alexander Schreyer

    Just added the RBZ version of this plugin. If you have SU v.8 M2 installed, give it a try!

  • Ee_en_nu

    thank very much

  • vodkins

    Can someone one great day make a plugin for real working grid? I cant work in GSU without grid. I've tried all "grid' plugins, but all of them are not exactly what i want. Look at 3dsmax or UnrealEd – thats are real grids!

  • Gerrit Hubers

    Hi Alex, have you made any updates to this script so inner (encapsulated) voids are taken into account the correct way?

    The workaround that I use now is to temporarily create a narrow "channel" to connect the hole with the outside, with empty space outside the outer perimeter. It works but is cumbersome and needs re-correcting geometry afterwards.

    TIA,
    Wo3Dan / Gerrit

    • http://intensedebate.com/people/alexschreyer alexschreyer

      Hi Gerrit,

      I intend to update my non-Ruby Editor plugins next, so this should happen soon.

      The fix I was working on last was similar in that I can separate the exterior vertices with outerloop and then create the channel automatically. I was getting stuck for cases where there were multiple internal voids.

      Cheers, Alex

      • Nico de Bruijn

        Hi Alex,

        Thans for the Ruby, makes my life a little easier!
        During the testing I'm experiencing the same problems as you have mentioned, even with only one void the measurement is incorrect. Hope you find the time to correct is soon. Have just another question. Isn't is possible during the calculation process thas the ucs is temporarily automaticly set on the plane that you are calculating. (maybe integrate another scritp). In working with large models it is very timeconsuming to set the plane (that is in Z-direction) on XY-0.
        And maybe it's an idear that the created centroidpoint can be exproted in 3D with the model to DWG.

        Thans anyway for your work!
        Nico

      • Nico de Bruijn

        Hi Alex,

        Thans for the Ruby, makes my life a little easier!
        During the testing I'm experiencing the same problems as you have mentioned, even with only one void the measurement is incorrect. Hope you find the time to correct is soon. Have just another question. Isn't is possible during the calculation process thas the ucs is temporarily automaticly set on the plane that you are calculating. (maybe integrate another scritp). In working with large models it is very timeconsuming to set the plane (that is in Z-direction) on XY-0.
        And maybe it's an idear that the created centroidpoint can be exproted in 3D with the model to DWG.

        Thans anyway for your work!
        Nico

  • http://www.neyses.de Michael Neyses

    I just needed this, very helpful Thanks

  • chris

    great plugin very simple to use

  • Shannon

    Terrific plugin – I have been looking for something like this for ages. How far off do you think you are at checking final accuracy? A metric version would be really terrific if that's possible. Thank you!!!!

    • http://intensedebate.com/people/alexschreyer alexschreyer

      I'll hopefully get to this soon…

      Cheers, Alex

  • billwheaton

    It looks like you got my message. I was debugging the code and noticed yesterday that fully enclosed polygons inside of other polygons don't work out right. Its because the vertices of any particular face don't differenciate the ones that are part of the outside, from the onces on the inside. A square offset within another square should have it's own centroid subtracted from the outer one. Likewise for multiple enclosed polygons their collective centroids should be subtracted from the outside polygon.

    The problem is, I don't know enough about ruby or the sketchup object model to know if they are kept separate somehow or if you just have to figure it out. But once that is known, it should be relatively straight forward.
    -Bill

    • http://intensedebate.com/people/alexschreyer alexschreyer

      Hi Bill, thanks for letting me know about this. Yes, it looks like a bug. I have to double-check the algorithm…
      More soon here…

      Cheers,
      Aelx

      • billwheaton

        I had some luck with face.loops. If you do what you did with each loopin the collection, then it works out great. They must have ordered the inside loops backwards, because you don't even have to subtract out the missing areas – its done automatically just by adding.

        But I don't know about the Moments of inertia. haven't gotten to that part yet. In fact, I don't know how I would use them, really. I'll have to admit ignorance. Aren't they a measure of stiffness in bending, and for figuring out how strong a structure will be, like a beam? I am sure its important to what I am trying to do though.

        I find the centroid helpful, because I am trying to find the balancing point of the various parts of a telescope mount I am making. Finding the 3d centroid would be really helpful for that. Not sure how in ruby though.
        -Bill

        • http://intensedebate.com/people/alexschreyer alexschreyer

          Thanks for looking so closely at it. Yes, the outside vertices run in one direction and the inside ones run in another. This takes care of the holes in both the centroid as well as the moment calculations. Both are nifty little algorithms that I found a while ago.

          I'll check tonight if I can make some changes to the code. The problem is that you have to use the same vertices when you are going from the outer loop to the inner loop and back – otherwise parts are missing.

          I have looked around for a 3D code. Would be great to have it, but I haven't been successful so far. I am assuming it would work similar (iterate through vertices).

  • http://S9K7 ali

    very good

  • Daniel

    Quando clico em download aprece um texto apenas e sem calquer opção p/ baixar.

    Oplugnis vem pelo e-mail e é free?

  • http://DEIELLS Daniel

    NÃO CONSIGO BAIXAR O PLUGN AO ENVIAR DA ERRO

  • http://www.alexschreyer.net Alex

    @Maurice: I know, I know… it’s on my to-do list for winter break!

  • Maurice Lang

    Thanks for the plugin.
    Can we have a metric version for the rest of the world please?

  • http://cnpag.org edgar farfan

    very good