Translate Page

Main Menu

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 2642 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.

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.

RATE POST: 1 Star2 Stars3 Stars4 Stars5 Stars
Loading ... Loading ...

This website uses IntenseDebate comments, but they are not currently loaded because either your browser doesn't support JavaScript, or they didn't load fast enough.

14 Responses to “Centroid and Area Properties Plugin for SketchUp”

  1. I just needed this, very helpful Thanks

  2. chris says:

    great plugin very simple to use

  3. Shannon says:

    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!!!!

  4. billwheaton says:

    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

    • alexschreyer says:

      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 says:

        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

        • alexschreyer says:

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

  5. Daniel says:

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

    Oplugnis vem pelo e-mail e é free?

  6. Daniel says:

    NÃO CONSIGO BAIXAR O PLUGN AO ENVIAR DA ERRO

  7. Alex says:

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

  8. Maurice Lang says:

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

Leave a Reply