I was just looking at this problem myself. My starting point was
http://www.thingiverse.com/thing:1481
http://www.thingiverse.com/thing:1481 which wraps 3 copies of an image
around a cylinder, then extrudes. There's about 15KB of Python source that
generates an OpenSCAD file. License on this is "Creative Commons -
Attribution - Non-Commercial". The author is Philipp Tiefenbacher
(wizard23). I've refactored his code a little, and extended it to include
conic surfaces, without really understanding how the underlying stuff
works.I haven't finished my tidy-up yet, but I'm happy to share (now or when
finished) as per Philipp's license. I'm new to openSCAD & Python (but a
long-time programmer) so my "tidy" may be less than your "tidy". I'm equally
happy for someone else to finish this off.If all you're interested in is
mapping text characters to a cylinder, then
http://www.thingiverse.com/thing:1661993 is useful.Frank
--
View this message in context: http://forum.openscad.org/Images-on-curved-cylindrical-surface-tp17823p17904.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
Turned out to be easier than I thought... because openSCAD now can handle
faces with more that 3 vertices, I could throw out all Philipp's stuff that
I didn't understand. Here's working version:
#!/usr/bin/python
import sys
import png
import urllib
from math import *
from pyopenscad import *
Commons - Attribution - Non-Commercial)
numRows = 0
numCols = 0
minRadius = 0
def getPNG(filename):
r=png.Reader(file=urllib.urlopen(filename))
data = r.read()
pixel = data[2]
raw = []
for row in pixel:
r = []
raw.append(r)
for px in row:
r.append(px)
return raw
surface of the cone. Where the cone is reasonably steep, this approximates
to how high
deeply it is recessed into the surface (negative z values)
top of the conic fragment. They may be equal for a cylinder, or topRadius
may be larger or smaller than bottomRadius.
minimum radius to map the image (e.g. the image is 256 pixels wide &&
bottomRadius < 40.74 (256/2*pi)), bottomRadius is increased
wrapped around (e.g. 0.25 means wrapi it around 90 degrees)
def projectCone(x, y, height, bottomRadius, topRadius, cylRange):
a = x2pi/numCols*cylRange
bottom radius of the cone
r = topRadius + (bottomRadius-topRadius) * (numRows-y)*1.0/numRows +
height
return [rcos(a), rsin(a), y]
def mapImage(pixMap, bottomRadius, topRadius):
minRadius=numCols/(2pi)
if (bottomRadius < minRadius):
bottomRadius = minRadius
cylRange = minRadius1.0/bottomRadius
pts = []
for y in xrange(0, numRows):
# Generate a "circle" of points for this layer
for x in xrange(0, numCols):
# Pixels range in value from 0-255, where 0 = black and 255 = white
p = projectCone(x, y, -pixMap[y][x]/255.0, bottomRadius, topRadius,
cylRange)
pts.append(p)
faces = []
bottom=[]
for x in xrange(0, numCols):
bottom.append(x)
bottom.append(0)
faces.append(bottom)
for y in range(0, numRows-1):
for x in range(0, numCols):
p1 = ynumCols+(x+1)%numCols
p2 = ynumCols+x
p3 = (y+1)*numCols+x
p4 = (y+1)*numCols + (x+1)%numCols
f = [p1, p2, p3, p4]
faces.append(f)
if (topRadius != 0):
top=[]
for x in xrange(0, numCols):
top.append(numRowsnumCols - x)
top.append(numRowsnumCols)
faces.append(top)
return polyhedron(pts, faces, 6)
if (len(sys.argv) !=4):
print "Usage: python ", sys.argv[0], "imgFile bottomRadius topRadius >
output.scad"
print "e.g. python ", sys.argv[0], "santa-claus-grey.png 45 0 >
santa.scad"
exit()
imgFile = sys.argv[1]
cone will be expanded to minRadius. If greater than minRadius, a D-shaped
partial cone will be produced
exactly once around the cone
coneRadius = float(sys.argv[2])
topRadius = float(sys.argv[3])
pixMap = getPNG(imgFile)
pixMap.reverse()
numCols = len(pixMap[0])
numRows = len(pixMap)
result = mapImage(pixMap, coneRadius, topRadius)
import time
print time.strftime("// Generated: %Y-%m-%d %H:%M")
print "// Source file: ", imgFile
print "// Image Height = ", numRows
print "// Image Width = ", numCols
print "// Minimum cylinder radius = ", minRadius
print "// Cylinder radius = ", coneRadius
print "$fa=2; $fs=0.5;\n"
print result.render()
On Mon, Jul 11, 2016 at 12:54 PM, frankv drifter.frank@gmail.com wrote:
View this message in context: Re: Images on curved (cylindrical) surface
http://forum.openscad.org/Images-on-curved-cylindrical-surface-tp17823p17904.html
Sent from the OpenSCAD mailing list archive http://forum.openscad.org/
at Nabble.com.
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
When I need to wrap a shape around a cylinder, I cut it in small pieces that
I reassemble on the cylinder.
The shape (here in orange) can be anything close to flat.
http://forum.openscad.org/file/n17908/wrap2.wrap2
Here is the code:
w=30; // radius of cylinder
h=100; // height of cylinder
//
// the pattern should be at [w,0,0] and move in y according to a
// pattern should be 2Pi * w size in Y
// Some rings...
//
module pattern0(a=0) {
for(i=[0:3]) {
translate([w,aPI/180w+iPI/2w+w,-20])
rotate([-90,0,-90])
difference() {
cylinder(d1=PI/2w+3,d2=0,h=80);
translate([0,0,-0.1]) cylinder(d1=PI/2w-3,d2=45+50,h=80);
}
}
}
// some text...
module pattern1(a=0) {
translate([w,aPI/180w,10])
rotate([90,0,90])
linear_extrude(height=5,convexity=2) text("bonjour!",32);
}
// rings and text...
module pattern2(a=0) {
pattern0(a);
pattern1(a);
}
module cutter(a=5,w=50,h=100) {
render()
intersection() {
rotate([0,0,-a/2]) translate([0,0,-h/2]) cube([w,50,h]);
rotate([0,0,a/2]) translate([0,-50,-h/2]) cube([w,50,h]);
}
}
%cylinder(r=w,h=h,center=true);
color("orange") translate([0,0,0]) pattern2(0);
step=5;
for( i=[0:step:360+2*step] ) {
rotate([0,0,i])
intersection() {
pattern2(-i);
cutter(step,w+20,h+20);
}
}
--
View this message in context: http://forum.openscad.org/Images-on-curved-cylindrical-surface-tp17823p17908.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
Would there be a way to package this in such a way that one could use it with
the Thingiverse customizer?
--
View this message in context: http://forum.openscad.org/Images-on-curved-cylindrical-surface-tp17823p18331.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
you can't wrap the python for custoizer but if you embed the scad code into
your single file. no problem. Customiser can't include or use any external
file except for the ones the website includes itself. over which you have no
control.
--
View this message in context: http://forum.openscad.org/Images-on-curved-cylindrical-surface-tp17823p18332.html
Sent from the OpenSCAD mailing list archive at Nabble.com.