将图像环绕在圆柱体周围 [英] Wrap an image around a cylinder

查看:36
本文介绍了将图像环绕在圆柱体周围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近有人问我是否可以打印一个侧面刻有自定义图像的手镯.

Someone asked me recently if I could print a bracelet with a custom image engraved on its side.

对我来说,问题很简单:我有一个 2d 笛卡尔系统 (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.在外部脚本中计算高度图并将值写入文件,例如'表面.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);}

编辑 28.10.2014:以另一种方式,您可以在矩阵中使用像素数据,通过 for 循环和矩阵迭代将像素一个像素地放置在手镯的圆周上.矩阵中的向量包含像素(x)、像素(y)和作为雕刻深度维度的灰度值/255.为了减少形状的数量,可以合并一列的像素,创建一个表示该列深度剖面的多边形并对其进行线性拉伸.在这种情况下,向量包含像素(x)和多边形的点矩阵.我用 Che 的已知图形成功地尝试了它.要生成矩阵,我使用 python3.4、PyQt5 和 Qt.QtGui.QImage.默认情况下,openscad 在 2000 个元素时关闭渲染.您可以在 Edit/Preferences/Advanced 下将其设置为所需的数字

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆