Public
Edited
Sep 28, 2023
Fork of CNC Face
Insert cell
Insert cell
Type JavaScript, then Shift-Enter. Ctrl-space for more options. Arrow ↑/↓ to switch modes.

Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
generateNotchedRectangleGcode = function () {
if (2 * radius > width || 2 * radius > height) {
throw new Error(
"Invalid parameters: The diameter of the notch (2*radius) must be less than the width and height of the rectangle."
);
}

const xCenter = 0;
const yCenter = 0;
const x0 = xCenter - width / 2;
const y0 = yCenter - height / 2;
const x1 = xCenter + width / 2;
const y1 = yCenter + height / 2;
const passDepth = cutDepth / passCount;

let gcode = `G00 Z0.5 F${movingFeedRate}
G00 X${x0 + radius} Y${y0} F${movingFeedRate}
G01 Z0 F50`;

for (let x = 0; x < passCount; x++) {
// Bottom-left notch
gcode += `
G02 X${x0} Y${y0 + radius} J${radius} F${cuttingFeedRate}
G01 X${x0} Y${y1 - radius} Z-${(x + 1) * passDepth}
G02 X${x0 + radius} Y${y1} I${radius}
G01 X${x1 - radius} Y${y1} F${cuttingFeedRate}
G02 X${x1} Y${y1 - radius} J-${radius}
G01 X${x1} Y${y0 + radius}
G02 X${x1 - radius} Y${y0} I-${radius}
G01 X${x0 + radius} Y${y0}\n`;
}

gcode += `
G02 X${x0} Y${y0 + radius} J${radius} F${cuttingFeedRate}
G01 X${x0} Y${y1 - radius} Z-${passCount * passDepth}
G02 X${x0 + radius} Y${y1} I${radius}
G01 X${x1 - radius} Y${y1} F${cuttingFeedRate}
G02 X${x1} Y${y1 - radius} J-${radius}
G01 X${x1} Y${y0 + radius}
G02 X${x1 - radius} Y${y0} I-${radius}
G01 X${x0 + radius} Y${y0}
G00 Z0.5 F${movingFeedRate}
G00 X0 Y0 F${movingFeedRate}
M30
`;

return gcode;
}
Insert cell
generateNotchedRectangleGcode()
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more