Created
February 20, 2025 04:57
-
-
Save JamesNewton/1829a4c22959c44b8f49b97dc413f2df to your computer and use it in GitHub Desktop.
OpenJSCAD.com code for a dial
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//makes a dial for export as a DXF or SVG | |
//needs finishing | |
let resolution = 64 | |
let slotfudge = 0.05 | |
let slotlength = 2 | |
function cutarc(r, a, i) { | |
let arcwidth = .1// a/2 | |
let curvedpath = CSG.Path2D.arc({ | |
center: [0,0,0], | |
radius: r, | |
startangle: a * i - arcwidth + slotfudge, | |
endangle: a * i + arcwidth, | |
resolution: resolution, | |
}); | |
let curvedpathin = CSG.Path2D.arc({ | |
center: [0,0,0], | |
radius: r-slotlength, | |
endangle: a * i - arcwidth, | |
startangle: a * i + arcwidth - slotfudge, | |
resolution: resolution, | |
}); | |
let curvedpath2 = curvedpath.concat(curvedpathin) | |
let curvedpathclosed = curvedpath2.close() | |
return curvedpathclosed.innerToCAG() | |
} | |
function cutarcs(degreerange, positions, r) { | |
let a = degreerange/positions //angle length of each arc | |
console.log(positions+" slots of "+a+" degrees") | |
curves = [] | |
for (let i = 0; i<positions+1; i+=2){ | |
curves.push(cutarc(r,a,i)) | |
} | |
return curves | |
} | |
function dial(degreesrange, positions, r) { | |
let curves = cutarcs(degreesrange, positions, r) | |
let radwidth = .1 | |
let dialbottom1 = CSG.Path2D.arc({ | |
center: [0,0,0], | |
radius: r-slotlength, | |
startangle: 0-radwidth+slotfudge, | |
endangle: degreesrange+radwidth, | |
resolution: resolution, | |
}); | |
let dialbottom2 = CSG.Path2D.arc({ | |
center: [0,0,0], | |
radius: r-slotlength-radwidth, | |
startangle: degreesrange - radwidth, | |
endangle: 0 + radwidth - slotfudge, | |
resolution: resolution, | |
}); | |
let dialbottom = dialbottom1.concat(dialbottom2).close().innerToCAG() | |
curves.push(dialbottom) | |
let dialtop1 = CSG.Path2D.arc({ | |
center: [0,0,0], | |
radius: r,//slotfudge, | |
startangle: 0-radwidth+slotfudge, | |
endangle: degreesrange+radwidth, | |
resolution: resolution, | |
}); | |
let dialtop2 = CSG.Path2D.arc({ | |
center: [0,0,0], | |
radius: r-radwidth, | |
startangle: degreesrange - radwidth, | |
endangle: 0 + radwidth - slotfudge, | |
resolution: resolution, | |
}); | |
let dialtop = dialtop1.concat(dialtop2).close().innerToCAG() | |
curves.push(dialtop) | |
return curves | |
} | |
function main () { | |
return dial(170, 40, 10) | |
//return cutarcs(170, 40, 10) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment