discuss@lists.openscad.org

OpenSCAD general discussion

View all threads

morph a rectangle to a circle

FP
Frank Paynter
Mon, Jul 12, 2021 11:59 PM

Thanks for all the help.  Here's the code I came up with to do this job.
Hope it helps someone else.

/*07/12/21 Pill dispenser adaptor for pill bottles
with various size caps. The cap fits into the top,
and the center of the cap is cut away to allow the
pills to fall down into the funnel.
This part gets mated with the actual dispenser
mechanism in TinkerCad
*/

rect_w = 12; //rectangle width
rect_l = 28; //rectangle height
th = 2; //wall thickness of the completed object
cyl_id = 56; //id to match pillbottle lid
cyl_od = cyl_id + 2*th; //outside diameter
ht = 16; //total height of morphed element
rect_h = 6; //height of just the rectangular solid
rim_ht = 6; //height of the collar above the morphed element
fn = 60; //number of sides making up cylinders

module cube_cyl(w,l,rect_h,dia, ht)
{
dh = 0.5;
echo(w = w, l = l, h = ht);
echo(rect_l = rect_l, rect_w = rect_w, rect_h = rect_h);

hull()

{
cube([w,l, dh], center=true);
translate ([0,0,ht]) cylinder (d=dia, h=0.5, $fn=fn);
}

translate ([0,0,-rect_h/2])cube([w,l,rect_h], center=true);
translate ([0,0,ht+rim_ht/2])cylinder(h=rim_ht, d=dia, center=true,
$fn=fn);
}

difference ()
{
cube_cyl(rect_w,rect_l, rect_h, cyl_od,ht);
color("green")
translate ([0,0,-0.5])cube_cyl(rect_w-th,rect_l-th,rect_h+th, cyl_id,ht+1);
}

[image: Screenshot 2021-07-12 195849.jpg]

G.Frank Paynter, PhD
OSU ESL Research Scientist (ret)
EM Workbench LLC
614 638-6749 (cell)

Thanks for all the help. Here's the code I came up with to do this job. Hope it helps someone else. /*07/12/21 Pill dispenser adaptor for pill bottles with various size caps. The cap fits into the top, and the center of the cap is cut away to allow the pills to fall down into the funnel. This part gets mated with the actual dispenser mechanism in TinkerCad */ rect_w = 12; //rectangle width rect_l = 28; //rectangle height th = 2; //wall thickness of the completed object cyl_id = 56; //id to match pillbottle lid cyl_od = cyl_id + 2*th; //outside diameter ht = 16; //total height of morphed element rect_h = 6; //height of just the rectangular solid rim_ht = 6; //height of the collar above the morphed element fn = 60; //number of sides making up cylinders module cube_cyl(w,l,rect_h,dia, ht) { dh = 0.5; echo(w = w, l = l, h = ht); echo(rect_l = rect_l, rect_w = rect_w, rect_h = rect_h); hull() { cube([w,l, dh], center=true); translate ([0,0,ht]) cylinder (d=dia, h=0.5, $fn=fn); } translate ([0,0,-rect_h/2])cube([w,l,rect_h], center=true); translate ([0,0,ht+rim_ht/2])cylinder(h=rim_ht, d=dia, center=true, $fn=fn); } difference () { cube_cyl(rect_w,rect_l, rect_h, cyl_od,ht); color("green") translate ([0,0,-0.5])cube_cyl(rect_w-th,rect_l-th,rect_h+th, cyl_id,ht+1); } [image: Screenshot 2021-07-12 195849.jpg] -- G.Frank Paynter, PhD OSU ESL Research Scientist (ret) EM Workbench LLC 614 638-6749 (cell)