将图像包裹在圆柱体上 [英] Wrap an image around a cylinder
问题描述
最近有人问我是否可以打印在手镯上刻有自定义图像的手镯。
Someone asked me recently if I could print a bracelet with a custom image engraved on its side.
对我来说,问题很简单:我有一个二维笛卡尔坐标系该系统(x,y)表示该人向我发送的矢量化图像的点。我想将它们视为3d圆柱系统(theta,r,z’),其中r为常数。最后,我想以通常的方式将此3d圆柱系统转换为3d笛卡尔系统(x',y',z')。
To me, the problem is simple: I have a 2d cartesian system (x,y) that expresses the points of the vectorized image the person sent me. I want to treat these as a 3d cylindrical system (theta, r, z') where r is constant. Finally, I want to convert this 3d cylindrical system to a 3d cartesian system (x',y',z') in the usual way.
所以:
z' = y
y' = r cos(x)
x' = r sin(x)
问题是我不知道如何将其表达为OpenSCAD。有一个使用multmatrix()进行矩阵变换的选项,但这仅允许进行线性变换-即,至少就我所知,我无法表达cos(x)之类的东西。
The problem is I don't know how to express this to OpenSCAD. There is an option for matrix transformation using multmatrix(), but this only allows for linear transformation - i.e. I can't express things like cos(x), at least to my knowledge.
我想要的是:
-
现有模块/ hack来表达这种变换,或者
an existing module/hack to express this transformation, or
一种执行逐顶点变换的通用方法,就像glsl中的顶点着色器
a generic method for performing per-vertex transformations, much like a vertex shader in glsl
至少,是否有可能确认OpenSCAD中不可用?
At very least, is it possible to confirm such things are not available in OpenSCAD?
推荐答案
,您可以使用 surface()
,请参见 http://en.wikibooks.org/wiki/OpenSCAD_User_Manual/The_OpenSCAD_Language#Surface 。在外部脚本中计算高度图,并将值写入文件中,例如 surface.dat。您可以平移和旋转生成的曲面,并在 difference()
中使用它。
you can use surface()
, see http://en.wikibooks.org/wiki/OpenSCAD_User_Manual/The_OpenSCAD_Language#Surface. Calculate the heightmap in an external script and write the values in a file, e.g. 'surface.dat'. you can translate and rotate the resulting surface and use it in difference()
.
我尝试使用此代码以及文档中的 surface.dat
I tried it with this code and the 'surface.dat' from documentation
difference() {
translate([0,0,5])cube([10,10,10], center =true);
rotate([0,0,90])surface(file = "surface.dat", center = true, convexity = 5);}
编辑2014年10月28日:
您可以使用矩阵中的pixeldata通过for循环在迭代过程中逐个像素地放置在手镯的圆周上矩阵。矩阵中的向量包含pixel(x),pixel(y)和灰度值/ 255作为雕刻深度的尺寸。为了减少形状的数量,可以合并一列的像素,以创建代表该列深度轮廓的多边形并将其线性拉伸。在这种情况下,向量包含多边形的pixel(x)和点矩阵。我用Che的已知图形成功地尝试了它。为了生成矩阵,我使用python3.4,PyQt5和Qt.QtGui.QImage。默认情况下,openscad关闭2000个元素的渲染。您可以在编辑/首选项/高级下将其设置为所需的数字
edit 28.10.2014: in another way you can use pixeldata in a matrix to place pixel by pixel on the circumference of the bracelet by a for loop and iteration over the matrix. The vectors in the matrix contain pixel(x), pixel(y) and the greyvalue/255 as dimension for depth of engraving. To reduce the number of shapes the pixels of one column can be pooled, creating a polygon representing the depth-profile of this column and linear-extrude it. In this case the vectors contain the pixel(x) and the pointmatrix of the polygon. I tried it successfully with the known graphic of Che. To generate the matrix i use python3.4, PyQt5 and Qt.QtGui.QImage. By default openscad turns off rendering at 2000 elements. You can set it to the needed number under Edit/Preferences/Advanced
openscad脚本:
the openscad-script:
include <./matrix_p.scad>;
difference() {
translate([-b,0,0]) rotate([0,90,0]) difference() {
cylinder(h = hb, r = rb, center = false);
translate([0,0,-0.5]) cylinder(h = hb+1, r = rb-tb, center = false);
}
for (val = m)
rotate([-ap*val[0],0,0]) translate([0,-rb-0.1,-ps/2]) linear_extrude(height = ps) polygon(points = val[1]);
}
在matrix_p.scad中设置的参数:
parameter set in matrix_p.scad:
// userinput
rb = 50; //radius bracelet
tb = 5; //thickness of b.
hb = 80; //height of b.
b = 10; //borderwidth beside engraving
// input from Qt.QtGui.QImage
iw = 590; //imagewidth in pixel
ih = 726; //height in pixel
ps = (hb-2*b)/ih; //scaling of pixel to fill the free place
ap = (ps*180)/(PI*rb); //angle per pixel
这篇关于将图像包裹在圆柱体上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!