replace circleCenter with point average

This commit is contained in:
Stewart Allen 2020-12-17 13:39:33 -05:00
commit fca3c43634

View file

@ -415,25 +415,32 @@
* @returns {Point} center of a polygon assuming it's a circle * @returns {Point} center of a polygon assuming it's a circle
*/ */
PRO.circleCenter = function() { PRO.circleCenter = function() {
let points = this.points, let x=0, y=0, l=this.points.length;
length = points.length, for (let point of this.points) {
incr = Math.floor(length / 3), x += point.x;
A = points[0], y += point.y;
B = points[incr], }
C = points[incr * 2], x /= l;
yDelta_a = B.y - A.y, y /= l;
xDelta_a = B.x - A.x, return newPoint(x, y, this.points[0].z, null);
yDelta_b = C.y - B.y, // let points = this.points,
xDelta_b = C.x - B.x, // length = points.length,
aSlope = yDelta_a / xDelta_a, // incr = Math.floor(length / 3),
bSlope = yDelta_b / xDelta_b, // A = points[0],
center = newPoint(0, 0, 0, null); // B = points[incr],
// C = points[incr * 2],
center.x = (aSlope * bSlope * (A.y - C.y) + bSlope * (A.x + B.x) - aSlope * (B.x+C.x) )/(2* (bSlope-aSlope) ); // yDelta_a = B.y - A.y,
center.y = -1 * (center.x - (A.x+B.x) / 2) / aSlope + (A.y + B.y) / 2; // xDelta_a = B.x - A.x,
center.z = A.z; // yDelta_b = C.y - B.y,
// xDelta_b = C.x - B.x,
return center; // aSlope = yDelta_a / xDelta_a,
// bSlope = yDelta_b / xDelta_b,
// center = newPoint(0, 0, 0, null);
//
// center.x = (aSlope * bSlope * (A.y - C.y) + bSlope * (A.x + B.x) - aSlope * (B.x+C.x) )/(2* (bSlope-aSlope) );
// center.y = -1 * (center.x - (A.x+B.x) / 2) / aSlope + (A.y + B.y) / 2;
// center.z = A.z;
// return center;
}; };
/** /**