[OpenSCAD] Images on curved (cylindrical) surface

David Eccles (gringer) bioinformatics at gringene.org
Wed Jun 29 15:02:09 EDT 2016


But there is also a programmatic solution with current OpenSCAD using some
windowing technique for discretization. Not the fastest but viable

I've got code for making pasta / pastry cutting rollers which imprint a
tessellating image on the surface of a cylinder. The simplest version is one
where the image needs no rotation and can tessellate by simple translation:

http://www.thingiverse.com/thing:1640712

<http://forum.openscad.org/file/n17837/katherine_roller.png> 

It uses hull operations to combine two cylinders at interpolated points
derived from the source polygon. Unfortunately I need to have an
explicitly-defined source polygon at the moment, as I couldn't find a way in
OpenSCAD to extract polygon paths from arbitrary objects. This can be
extracted from SVG paths and pasted into the OpenSCAD code, but it's not
particularly easy for a first-timer to do that.

    pr=20; // pattern radius
    pi=3.1415927;
    cr=3*pr/sin(60)/(2*pi); // cylinder radius
    pf=0.2; // relative size of edge points
    
    // Flattens an array down one level (removing the enclosing array)
    function flatten(pointArray, done=0, res=[]) =
        (done == len(pointArray)) ?
            res :
            flatten(pointArray=pointArray, done=done+1, 
                res=concat(res,pointArray[done]));
                
    // linear interpolation between two points, excludes last point
    function intp(p1, p2, thr=0.5, res = []) = 
        (norm(p2-p1) <= thr) ? concat(res,[p1]) :
            intp(p1=p1 + (thr/norm(p2-p1)) * (p2-p1), p2=p2, 
                thr=thr, res = concat(res,[p1]));
    
    kath_poly = flatten([ for(i=[-30:60:329]) [ 
            [pr*cos(i)-pr*pf*cos(i),pr*sin(i)-pr*pf*sin(i)],
            [pr*cos(i),pr*sin(i)],
            [pr*cos(i)+pr*pf*cos(i+60),pr*sin(i)+pr*pf*sin(i+60)] ]]);
    
    int_kath = flatten([for(i = [0:(len(kath_poly)-1)]) 
            intp(p1=kath_poly[i], p2=kath_poly[(i+1) % len(kath_poly)],
thr=2)]);
    
    cyl_kath = [ for(i = [0:(len(int_kath)-1)])
      [(cr)*cos(int_kath[i][0]/cr * 180/pi),(cr)*sin(int_kath[i][0]/cr *
180/pi),-int_kath[i][1]] ];
    
    module 3d_kath(){
        for(i = [0:(len(cyl_kath)-1)]){
            hull(){
                translate(cyl_kath[i])
                    rotate(int_kath[i][0]/cr * 180/pi) rotate([90,0,90])
                        translate([0,0,1])
                            cylinder(r1=2, r2=0, h=4, $fn=4, center=true);
                translate(cyl_kath[(i+1) % len(cyl_kath)])
                    rotate(int_kath[(i+1) % len(cyl_kath)][0]/cr * 180/pi)
rotate([90,0,90]) 
                        translate([0,0,1])
                            cylinder(r1=2, r2=0, h=4, $fn=4, center=true);
            }
        }
    }
    
    module kath_roller(){
        cylinder(r=cr, h=110, center=true);
        3d_kath();
        rotate(180) 3d_kath();
        translate([0,0,1.5*pr]) rotate(90) 3d_kath();
        translate([0,0,1.5*pr]) rotate(270) 3d_kath();
        translate([0,0,-1.5*pr]) rotate(90) 3d_kath();
        translate([0,0,-1.5*pr]) rotate(270) 3d_kath();
    }

    kath_roller();




--
View this message in context: http://forum.openscad.org/Images-on-curved-cylindrical-surface-tp17823p17837.html
Sent from the OpenSCAD mailing list archive at Nabble.com.




More information about the Discuss mailing list