center of gravity

Use this forum to ask questions about how to do things in QCAD.

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Attach drawing files and screenshots.

Post one question per topic.

Post Reply
greed
Newbie Member
Posts: 5
Joined: Thu Sep 28, 2017 5:29 pm

center of gravity

Post by greed » Tue Oct 03, 2017 5:38 pm

How can I find the geometric center of a polygon ?
How would I find the center of gravity or geometric center of two separated polygons ?
I'm trying to find the CLR (center of lateral resistance and the CE (center of effort ) on a sailboat plan.

User avatar
andrew
Site Admin
Posts: 9037
Joined: Fri Mar 30, 2007 6:07 am

Re: center of gravity

Post by andrew » Tue Oct 03, 2017 5:43 pm

I'm afraid QCAD does not include tools to compute any of these specific points.

CVH
Premier Member
Posts: 3417
Joined: Wed Sep 27, 2017 4:17 pm

Re: center of gravity

Post by CVH » Sat Jun 02, 2018 4:18 pm

https://en.wikipedia.org/wiki/Centroid
Sroll down to
Centroid of a polygon

CVH
Premier Member
Posts: 3417
Joined: Wed Sep 27, 2017 4:17 pm

Re: center of gravity

Post by CVH » Wed Oct 20, 2021 8:20 am

Andrew,

Stumbled on:
InfoPolylineArea.prototype.getCenter()
InfoArea.prototype.getCenter()

As far as I can tell that is the centroid of a non-self-intersecting closed polygon defined by n vertices.
Added to QCAD on May 11, 2016 :!:

But here only valid for polygons with CW orientation.
There the getArea() returns an absolute value and the polygon is assumed to be CCW.
Seems contradictory ...

The source in the wiki defines the area of a polygon as:
http://paulbourke.net/geometry/polygonmesh/
-> "Calculating the area and centroid of a polygon"

polyarea6.gif
polyarea6.gif (2.67 KiB) Viewed 5867 times
And that seems to not match with:

Code: Select all

    var j = nPts - 1;
    for (var i = 0; i < nPts; j = i++) {
        p1 = pts[i];
        p2 = pts[j];
        area += p1.x * p2.y;
        area -= p1.y * p2.x;
    }
    area /= 2;
There p2 is the previous point and not the next point aka (xi+1, yi+1)

Same goes for the centroid formula and the js code of both the getCenter() mentioned above:
polyarea5.gif
polyarea5.gif (5.28 KiB) Viewed 5867 times

Bottom line:
When I swap p1 and p2 and allow for negative values for the area then all turns to be OK.

Further simplified there both getCenter & getArea iterate the same point cloud and value f can be summed to the signed area:

Code: Select all

InfoArea.prototype.getCenter = function() {
    var pts = this.polyline.getVertices();
    var nPts = pts.length;
    var x = 0;
    var y = 0;
    var f;
    var j = nPts - 1;
    var p1;
    var p2;
    var area = 0;

    for (var i = 0; i < nPts; j = i++) {
        p2 = pts[i];
        p1 = pts[j];
        f = p1.x * p2.y - p2.x * p1.y;
        x += (p1.x + p2.x) * f;
        y += (p1.y + p2.y) * f;
        area += f;
    }

    f = area * 3;
    return new RVector(x / f, y / f);
};
Regards,
CVH

User avatar
andrew
Site Admin
Posts: 9037
Joined: Fri Mar 30, 2007 6:07 am

Re: center of gravity

Post by andrew » Wed Oct 20, 2021 10:02 am

Thanks, looks indeed like a bit of orphaned code. I've removed it.

CVH
Premier Member
Posts: 3417
Joined: Wed Sep 27, 2017 4:17 pm

Re: center of gravity

Post by CVH » Wed Oct 20, 2021 10:56 am

My intention was to correct it and include it as the centroid position of a polygon ...
Pitty...
CVH

User avatar
andrew
Site Admin
Posts: 9037
Joined: Fri Mar 30, 2007 6:07 am

Re: center of gravity

Post by andrew » Wed Oct 20, 2021 11:17 am

Yes, I might get back to this if time allows...

guyrinf
Newbie Member
Posts: 7
Joined: Wed Apr 16, 2014 12:51 pm

Re: center of gravity

Post by guyrinf » Wed Oct 20, 2021 11:33 am

operating system: Ubuntu 18.04
Qcad 3.26.4.9

Too bad, I have to use Turbocad to find the center of gravity. It would be so good to include it in Qcad. I often work with sailboat plans on Qcad.

CVH
Premier Member
Posts: 3417
Joined: Wed Sep 27, 2017 4:17 pm

Re: center of gravity

Post by CVH » Fri Oct 29, 2021 12:01 pm

guy,

Please refer to:
viewtopic.php?t=8846

Regards,
CVH

Post Reply

Return to “QCAD 'How Do I' Questions”