discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Re: [OpenSCAD] Images on curved (cylindrical) surface

M
MichaelAtOz
Wed, Jun 29, 2016 5:22 AM

Lukas wrote

Hi,

I am just getting started with OpenSCAD and just found the feature to
import images via an Inkscape extension. But the tutorials I found only
show the import/editing of flat images.

Is there any chance to put this flat image onto a curved surface such as a
cylinder?

Hope the question makes sense...

Thanks,
Lukas

AFAIK no, not if you mean like wrapping a label around an object.
If the image is like a line drawing, you could linear_extrude it & intersect
it with a hollow cylinder, but the result would be contorted.
Or you could slice it up and move the bits around, but the maths would be
beyond me.


Admin - PM me if you need anything, or if I've done something stupid...

Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above.

The TPP is no simple “trade agreement.”  Fight it! http://www.ourfairdeal.org/  time is running out!

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

Lukas wrote > Hi, > > I am just getting started with OpenSCAD and just found the feature to > import images via an Inkscape extension. But the tutorials I found only > show the import/editing of flat images. > > Is there any chance to put this flat image onto a curved surface such as a > cylinder? > > Hope the question makes sense... > > Thanks, > Lukas AFAIK no, not if you mean like wrapping a label around an object. If the image is like a line drawing, you could linear_extrude it & intersect it with a hollow cylinder, but the result would be contorted. Or you could slice it up and move the bits around, but the maths would be beyond me. ----- Admin - PM me if you need anything, or if I've done something stupid... Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above. The TPP is no simple “trade agreement.” Fight it! http://www.ourfairdeal.org/ time is running out! -- View this message in context: http://forum.openscad.org/Images-on-curved-cylindrical-surface-tp17823p17824.html Sent from the OpenSCAD mailing list archive at Nabble.com.
P
Parkinbot
Wed, Jun 29, 2016 11:35 AM

And it would be so easy, once one could get (programmatically) hands on the
DXF representation in OpenSCAD ...

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

http://forum.openscad.org/file/n17832/geschafft1.png
http://forum.openscad.org/file/n17832/geschafft2.png

R = 45;  // radius
H = 2;  // height
L = 130; // centering offset
step = 5;

$fn=360/step;

for (i=[0:step:360])
{
radian = RPI/180;
rotate([0, i, 0])  translate([0,0,R-H/2]) // cylinder stuff
intersection()
{
translate([L-i
radian, 0, 0])  // shift dxf over the window
linear_extrude(height = H, center = true, convexity = 4)
import("geschafft.dxf");
cube([radian*step, 100, H+1], center = true);  // window
}
}

color("black", .7)
rotate([90, 0, 0])
cylinder(r=R-H, h = 100, center = true);

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

And it would be so easy, once one could get (programmatically) hands on the DXF representation in OpenSCAD ... But there is also a programmatic solution with current OpenSCAD using some windowing technique for discretization. Not the fastest but viable: <http://forum.openscad.org/file/n17832/geschafft1.png> <http://forum.openscad.org/file/n17832/geschafft2.png> > R = 45; // radius > H = 2; // height > L = 130; // centering offset > step = 5; > > $fn=360/step; > > for (i=[0:step:360]) > { > radian = R*PI/180; > rotate([0, i, 0]) translate([0,0,R-H/2]) // cylinder stuff > intersection() > { > translate([L-i*radian, 0, 0]) // shift dxf over the window > linear_extrude(height = H, center = true, convexity = 4) > import("geschafft.dxf"); > cube([radian*step, 100, H+1], center = true); // window > } > } > > color("black", .7) > rotate([90, 0, 0]) > cylinder(r=R-H, h = 100, center = true); -- View this message in context: http://forum.openscad.org/Images-on-curved-cylindrical-surface-tp17823p17832.html Sent from the OpenSCAD mailing list archive at Nabble.com.
DE
David Eccles (gringer)
Wed, Jun 29, 2016 7:02 PM

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.

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.
N
Neon22
Wed, Jun 29, 2016 10:44 PM

However it is easy for a first timer to use unkscape to create the svg and
the openscad export tool to create polygon lists.

@david can you adjust your code to take those lists ?

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

However it is easy for a first timer to use unkscape to create the svg and the openscad export tool to create polygon lists. - http://www.thingiverse.com/thing:1065500 @david can you adjust your code to take those lists ? -- View this message in context: http://forum.openscad.org/Images-on-curved-cylindrical-surface-tp17823p17839.html Sent from the OpenSCAD mailing list archive at Nabble.com.