center of gravity
Moderator: andrew
Forum rules
Always indicate your operating system and QCAD version.
Attach drawing files and screenshots.
Post one question per topic.
Always indicate your operating system and QCAD version.
Attach drawing files and screenshots.
Post one question per topic.
center of gravity
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.
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.
Re: center of gravity
I'm afraid QCAD does not include tools to compute any of these specific points.
Re: center of gravity
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"
And that seems to not match with:
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:
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:
Regards,
CVH
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"
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;
Same goes for the centroid formula and the js code of both the getCenter() mentioned above:
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);
};
CVH
Re: center of gravity
Thanks, looks indeed like a bit of orphaned code. I've removed it.
Re: center of gravity
My intention was to correct it and include it as the centroid position of a polygon ...
Pitty...
CVH
Pitty...
CVH
Re: center of gravity
Yes, I might get back to this if time allows...
Re: center of gravity
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.
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.