checkpoint arc work
This commit is contained in:
parent
1e33774630
commit
3dedaae05b
3 changed files with 31 additions and 27 deletions
|
|
@ -376,6 +376,27 @@
|
|||
return center;
|
||||
}
|
||||
|
||||
/**
|
||||
* return two possible circle centers given two points and a radius
|
||||
* https://stackoverflow.com/questions/36211171/finding-center-of-a-circle-given-two-points-and-radius
|
||||
*/
|
||||
function center2pr(p1, p2, r) {
|
||||
let x1 = p1.x,
|
||||
x2 = p2.x,
|
||||
y1 = p1.y,
|
||||
y2 = p2.y,
|
||||
q = Math.sqrt(Math.pow((x2-x1),2) + Math.pow((y2-y1),2)),
|
||||
y3 = (y1+y2)/2,
|
||||
x3 = (x1+x2)/2,
|
||||
basex = Math.sqrt(Math.pow(r,2)-Math.pow((q/2),2))*(y1-y2)/q, //calculate once
|
||||
basey = Math.sqrt(Math.pow(r,2)-Math.pow((q/2),2))*(x2-x1)/q, //calculate once
|
||||
centerx1 = x3 + basex, //center x of circle 1
|
||||
centery1 = y3 + basey, //center y of circle 1
|
||||
centerx2 = x3 - basex, //center x of circle 2
|
||||
centery2 = y3 - basey; //center y of circle 2
|
||||
return [{x:centerx1, y:centery1}, {x:centerx2, y:centery2}];
|
||||
}
|
||||
|
||||
function thetaDiff(n1, n2, sign) {
|
||||
let diff = n2 - n1;
|
||||
while (diff < -Math.PI) diff += Math.PI * 2;
|
||||
|
|
@ -468,6 +489,7 @@
|
|||
area2,
|
||||
center2d,
|
||||
center3d,
|
||||
center2pr,
|
||||
thetaDiff,
|
||||
distSq : dist2,
|
||||
distSqv2 : dist2v2,
|
||||
|
|
|
|||
|
|
@ -157,24 +157,15 @@
|
|||
center.y = pos.Y + rec.J;
|
||||
//center.r = TODO
|
||||
} else if (rec.R !== undefined) {
|
||||
let mid = {
|
||||
x: (pos.X + rec.X) / 2,
|
||||
y: (pos.Y + rec.Y) / 2,
|
||||
dx: rec.X - pos.X,
|
||||
dy: rec.Y - pos.Y
|
||||
};
|
||||
let hml = Math.sqrt(mid.dx * mid.dx + mid.dy * mid.dy);
|
||||
let s2 = BASE.newSlope({
|
||||
let pr2 = BASE.util.center2pr({
|
||||
x: pos.X,
|
||||
y: pos.Y
|
||||
}, {
|
||||
x: rec.X,
|
||||
y: rec.Y
|
||||
}).normal().toUnit();
|
||||
let ln = Math.sqrt(Math.abs(rec.R*rec.R - hml*hml));
|
||||
LOG({hml,s2,ln,mid});
|
||||
center.x = mid.x - ln * s2.dx;
|
||||
center.y = mid.y - ln * s2.dy;
|
||||
}, rec.R)[g2 ? 1 : 0];
|
||||
center.x = pr2.x;
|
||||
center.y = pr2.y;
|
||||
center.r = rec.R;
|
||||
} else {
|
||||
console.log({malfomed_arc: line});
|
||||
|
|
@ -186,34 +177,24 @@
|
|||
// let a1 = Math.atan2(center.y - pos.Y, center.x - pos.X);
|
||||
// let a2 = Math.atan2(center.y - rec.Y, center.x - rec.X);
|
||||
let ad = BASE.util.thetaDiff(a1, a2);
|
||||
let steps = 5;
|
||||
let steps = 20;
|
||||
let step = (ad > 0.001 ? ad : Math.PI * 2) / steps;
|
||||
let rot = a1;
|
||||
let d1 = a1 * 180/Math.PI;
|
||||
let d2 = a2 * 180/Math.PI;
|
||||
|
||||
LOG({pos, rec, center, a1, a2, ad, d1, d2, step, rot});
|
||||
LOG({first: pos, last: rec, center, a1, a2, ad, step, rot, line});
|
||||
G0G1(false, [`X${center.x}`, `Y${center.y}`, `E1`]);
|
||||
|
||||
// rotate p around o
|
||||
// p'x = cos(theta) * (px-ox) - sin(theta) * (py-oy) + ox
|
||||
// p'y = sin(theta) * (px-ox) + cos(theta) * (py-oy) + oy
|
||||
|
||||
let pc = { X: pos.X, Y: pos.Y };
|
||||
// let zc = { x: pc.X - center.x, y: pc.Y - center.y };
|
||||
for (let i=0; i<=steps; i++) {
|
||||
let np = {
|
||||
X: center.x + Math.sin(rot) * center.r,
|
||||
Y: center.y + Math.cos(rot) * center.r
|
||||
// X: Math.cos(rot) * (pc.X - center.x) - Math.sin(rot) * (pc.Y - center.y) + center.x,
|
||||
// Y: Math.sin(rot) * (pc.X - center.x) - Math.cos(rot) * (pc.Y - center.y) + center.y
|
||||
};
|
||||
rot += step;
|
||||
G0G1(false, [`X${np.X}`, `Y${np.Y}`, `E1`]);
|
||||
}
|
||||
|
||||
G0G1(false, [`X${rec.X}`, `Y${rec.Y}`, `E1`]);
|
||||
LOG({g2, arc: line, pos, center});
|
||||
|
||||
pos.X = rec.X;
|
||||
pos.Y = rec.Y;
|
||||
|
|
|
|||
|
|
@ -508,7 +508,7 @@
|
|||
let from = arcQ[0];
|
||||
let to = arcQ.peek();
|
||||
let cc = {x:0, y:0, z:0, r:0};
|
||||
let cl = arcQ.length;
|
||||
let cl = arcQ.center.length;
|
||||
for (let center of arcQ.center) {
|
||||
cc.x += center.x;
|
||||
cc.y += center.y;
|
||||
|
|
@ -521,6 +521,7 @@
|
|||
cc.r /= cl;
|
||||
// first arc point
|
||||
emitQrec(from);
|
||||
console.log({first: from, last: arcQ.peek(), center: cc});
|
||||
// rest of arc to final point
|
||||
let dist = arcQ.slice(1).map(v => v.dist).reduce((a,v) => a+v);
|
||||
let emit = from.e;//arcQ.slice(1).map(v => v.e).reduce((a,v) => a+v);
|
||||
|
|
@ -533,7 +534,7 @@
|
|||
let gc = area > 0 ? 'G2' : 'G3';
|
||||
let pre = `${gc} X${to.x.toFixed(decimals)} Y${to.y.toFixed(decimals)} R${cc.r.toFixed(decimals)} E${emit.toFixed(decimals)}`;
|
||||
let add = pos.f !== from.speedMMM ? ` E${from.speedMMM}` : '';
|
||||
append(`${pre}${add} ; merged=${cl-1} dist=${dist.toFixed(decimals)}`);
|
||||
append(`${pre}${add} ; merged=${cl-1} len=${dist.toFixed(decimals)} cp=${cc.x.round(2)},${cc.y.round(2)}`);
|
||||
pos.x = to.x;
|
||||
pos.y = to.y;
|
||||
pos.z = to.z;
|
||||
|
|
|
|||
Loading…
Reference in a new issue