cheat circle center calc. alert on isNaN circle center
This commit is contained in:
parent
e8138269f5
commit
77b9ddfd91
2 changed files with 21 additions and 48 deletions
|
|
@ -316,40 +316,23 @@
|
||||||
return (d2y * d1x) - (d2x * d1y);
|
return (d2y * d1x) - (d2x * d1y);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
function circleCenter(A,B,C)
|
||||||
* return circle center given three points
|
{
|
||||||
* from https://math.stackexchange.com/questions/1076177/3d-coordinates-of-circle-center-given-three-point-on-the-circle
|
let yDelta_a = B.y - A.y;
|
||||||
*/
|
let xDelta_a = B.x - A.x;
|
||||||
function center3d(a,b,c) {
|
let yDelta_b = C.y - B.y;
|
||||||
let ax = a.x,
|
let xDelta_b = C.x - B.x;
|
||||||
ay = a.y,
|
let center = {z: A.z};
|
||||||
az = a.z || 0,
|
if (!xDelta_a) xDelta_a = 0.00000000001; // cheat!
|
||||||
bx = b.x,
|
if (!xDelta_b) xDelta_b = 0.00000000001; // cheat!
|
||||||
by = b.y,
|
let aSlope = yDelta_a / xDelta_a;
|
||||||
bz = b.z || 0,
|
let bSlope = yDelta_b / xDelta_b;
|
||||||
cx = c.x,
|
center.x = (aSlope*bSlope*(A.y - C.y) + bSlope*(A.x + B.x) - aSlope*(B.x+C.x) )/(2* (bSlope-aSlope) );
|
||||||
cy = c.y,
|
center.y = -1*(center.x - (A.x+B.x)/2)/aSlope + (A.y+B.y)/2;
|
||||||
cz = c.z || 0,
|
// if (isNaN(center.x)) {
|
||||||
Cx = bx-ax,
|
// console.log({xDelta_a, xDelta_b, aSlope, bSlope});
|
||||||
Cy = by-ay,
|
// }
|
||||||
Cz = bz-az,
|
return center;
|
||||||
Bx = cx-ax,
|
|
||||||
By = cy-ay,
|
|
||||||
Bz = cz-az,
|
|
||||||
B2 = (ax*ax)-(cx*cx)+(ay*ay)-(cy*cy)+(az*az)-(cz*cz),
|
|
||||||
C2 = (ax*ax)-(bx*bx)+(ay*ay)-(by*by)+(az*az)-(bz*bz),
|
|
||||||
CByz = Cy*Bz-Cz*By,
|
|
||||||
CBxz = Cx*Bz-Cz*Bx,
|
|
||||||
CBxy = Cx*By-Cy*Bx,
|
|
||||||
ZZ1 = -(Bz-Cz*Bx/Cx)/(By-Cy*Bx/Cx),
|
|
||||||
Z01 = -(B2-Bx/Cx*C2)/(2*(By-Cy*Bx/Cx)),
|
|
||||||
ZZ2 = -(ZZ1*Cy+Cz)/Cx,
|
|
||||||
Z02 = -(2*Z01*Cy+C2)/(2*Cx),
|
|
||||||
dz = -((Z02-ax)*CByz-(Z01-ay)*CBxz-az*CBxy)/(ZZ2*CByz-ZZ1*CBxz+CBxy),
|
|
||||||
dx = ZZ2*dz + Z02,
|
|
||||||
dy = ZZ1*dz + Z01;
|
|
||||||
|
|
||||||
return {x:dx, y:dy, z:dz};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -357,21 +340,11 @@
|
||||||
* from https://stackoverflow.com/questions/4103405/what-is-the-algorithm-for-finding-the-center-of-a-circle-from-three-points
|
* from https://stackoverflow.com/questions/4103405/what-is-the-algorithm-for-finding-the-center-of-a-circle-from-three-points
|
||||||
*/
|
*/
|
||||||
function center2d(A,B,C,rad) {
|
function center2d(A,B,C,rad) {
|
||||||
// let yDelta_a = B.y - A.y,
|
let center = circleCenter(A,B,C);
|
||||||
// xDelta_a = B.x - A.x,
|
|
||||||
// yDelta_b = C.y - B.y,
|
|
||||||
// xDelta_b = C.x - B.x,
|
|
||||||
// aSlope = yDelta_a/xDelta_a,
|
|
||||||
// bSlope = yDelta_b/xDelta_b,
|
|
||||||
// center = {x:0, y:0, z:0};
|
|
||||||
// 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;
|
|
||||||
let center = center3d(A,B,C);
|
|
||||||
if (rad) {
|
if (rad) {
|
||||||
let dx = center.x - A.x;
|
let dx = center.x - A.x;
|
||||||
let dy = center.y - A.y;
|
let dy = center.y - A.y;
|
||||||
center.r = Math.sqrt(dx*dx + dy*dy)
|
center.r = Math.sqrt(dx*dx + dy*dy)
|
||||||
// if (isNaN(center.r)) console.log('NaN',{dx,dy,A,B,C,center,xDelta_a,xDelta_b,yDelta_a,yDelta_b,aSlope,bSlope});
|
|
||||||
}
|
}
|
||||||
return center;
|
return center;
|
||||||
}
|
}
|
||||||
|
|
@ -488,7 +461,6 @@
|
||||||
round,
|
round,
|
||||||
area2,
|
area2,
|
||||||
center2d,
|
center2d,
|
||||||
center3d,
|
|
||||||
center2pr,
|
center2pr,
|
||||||
thetaDiff,
|
thetaDiff,
|
||||||
distSq : dist2,
|
distSq : dist2,
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@
|
||||||
timeDwell = retDwell / 1000,
|
timeDwell = retDwell / 1000,
|
||||||
peelGuard = process.outputPeelGuard || 0,
|
peelGuard = process.outputPeelGuard || 0,
|
||||||
arcDist = isBelt || !isDanger ? 0 : (process.arcTolerance || 0),
|
arcDist = isBelt || !isDanger ? 0 : (process.arcTolerance || 0),
|
||||||
arcMax = 1,
|
arcMax = 300,
|
||||||
originCenter = process.outputOriginCenter,
|
originCenter = process.outputOriginCenter,
|
||||||
offset = originCenter ? null : {
|
offset = originCenter ? null : {
|
||||||
x: device.bedWidth/2,
|
x: device.bedWidth/2,
|
||||||
|
|
@ -524,7 +524,8 @@
|
||||||
let e1 = arcQ[el-3]; // third last in arcQ
|
let e1 = arcQ[el-3]; // third last in arcQ
|
||||||
let e2 = arcQ[el-2]; // second last in arcQ
|
let e2 = arcQ[el-2]; // second last in arcQ
|
||||||
let e3 = arcQ[el-1]; // last in arcQ
|
let e3 = arcQ[el-1]; // last in arcQ
|
||||||
let cc = BASE.util.center2d(e1, e2, e3, 1); //
|
let cc = BASE.util.center2d(e1, e2, e3, 1); // find center
|
||||||
|
if (isNaN(cc.x)) console.log({cc, e1, e2, e3});
|
||||||
let dc = 0;
|
let dc = 0;
|
||||||
if (arcQ.length === 3) {
|
if (arcQ.length === 3) {
|
||||||
arcQ.center = [ cc ];
|
arcQ.center = [ cc ];
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue