howdy all,
i host a few pages where folks can determine the diameter of sphere to resonate a given frequency and then 3d print them if they wish using openjscad. i originally wrote some code with openscad before i was aware of openjscad. i have been able to port the code over from openscad, however there is some functionality i haven't been able convert from openscad. as shown below, with the openscad code i was able to provide an area where visitors are able to enter the variables and then the remainder of the code processes those variables. with jscad, i have been unable to provide the same functionality and therefor visitors must edit throughout the code directly with whatever instructions i can provide to make it not too confusing. there are two sphere types. one has a sound hole and the other has a tube elongating the sound hole. below is what i have done for each type.
Sphere with a sound hole -
OPENSCAD:
// Example A 440Hz
// fragment number
$fn=100;
// Enter sphere diameter
sd=143.38;
// Enter wall thickness
wt=2;
// Enter sound hole diameter.
sh=25;
difference() {
sphere(d=sd+(2wt));
sphere(d=sd);
translate([0,0,-sd/2-wt])cylinder(d=sh,h=wt2);
}
JSCAD:
// Example A 440Hz
// BEGINNING OF CODE
function
main() {
return [
// Enter radius of sphere plus 2 for r:
difference(sphere({r: 47, center:true, fn: 100}),
// Enter radius of sphere for r:
sphere({r: 45, center:true, fn: 100}),
// Enter radius of sound hole for r: and h= -radius of first sphere
cylinder({r: 12.5, h: -47})),
];
}
// END OF CODE
Sphere with tube -
OPENSCAD:
// Example: A 220Hz
// fragment number
$fn=100;
// Enter sphere diameter.
sd=132.47;
// Enter Sound Hole Diameter.
sh=25;
// Enter length of neck
ln=25;
// Enter wall Thickness
wt=2;
// SPHERE
difference() {
sphere(d=sd+(2wt));
sphere(d=sd);
translate([0,0,-(sd/2)-wt])cylinder(d=sh,h=wt2);
}
// NECK
difference() {
translate([0,0,-ln-(sd/2)+wt])cylinder(d=sh+(2*wt),h=ln);
translate([0,0,-ln-(sd/2)+wt])cylinder(d=sh,h=ln);
}
JSCAD:
// Example: A 440Hz
// BEGINNING OF CODE
function
main() {
return [
// Sphere1. Enter radius of sphere +2 for r:
difference(sphere({r: 35, center:true, fn: 100}),
// Sphere2. Enter radius of sphere for r:
sphere({r: 33, center:true, fn: 100}),
// Enter radius of sound hole for r: and radius of sphere1 for h:
cylinder({r: 12.5, h: -35, fn: 100})),
// Enter radius of sound hole +2 for r:
// Enter length of neck for h:
// Enter radius of sphere2 plus height of neck
// minus 2x wall thickness(2x2=4 in this example) for .translate
difference(cylinder({r: 14.5, h: 25, fn: 100}).translate([0,0,-54]),
// Enter radius of sound hole for r:
// Enter length of neck for h:
// Enter radius of sphere2 plus height of neck
// minus 2x wall thickness(2x2=4 in this example) for .translate
cylinder({r: 12.5, h: 25, fn: 100}).translate([0,0,-54])),
];
}
// END OF CODE
i would love for visitors to be able to simply define the variables of sphere radius or diameter, sound hole diameter, tube length, wall thickness, and fragment number and then let the code do the rest.
thank you for any insights you can offer.