JustinSDK / dotSCAD

Reduce the burden of mathematics when playing OpenSCAD
https://openhome.cc/zh-tw/openscad/
GNU Lesser General Public License v3.0
784 stars 107 forks source link

Can't make a seamless surface (cylinder) with sf_bend #24

Closed nesdnuma closed 2 years ago

nesdnuma commented 2 years ago

Hello,

I am trying to use a picture to emboss a cylinder. So I have tried with sf_bend and a 360° angle. However I can't get a seamless junction at the edges even if the pixels on each border of the picture do have the same value. I have also tried with angles slightly bigger or smaller than 360° but it doesn't function.

JustinSDK commented 2 years ago

The sf_bend doesn't intend to do the task you want. Turn levels into sections and sweep them.

invert = false;
radius = 30;
thickness = 10;
depth = 5;
levels = [....]; // your levels

sf_cylinder(levels, radius, thickness, depth, invert);

use <sweep.scad>;

module sf_cylinder(levels, radius, thickness, depth, invert = false, convexity = 1) {
    row_leng = len(levels[0]);
    a_step = 360 / row_leng;
    d_scale = (invert ? -depth : depth) / 255;
    or = thickness + (invert ? radius + depth : radius - depth);
    ir = radius;
    row_range = [0:row_leng - 1];

    sections = [
        for(z = [0:len(levels) - 1]) 
            concat(
                [for(xi = row_range)
                    let(
                        r = or + levels[z][xi] * d_scale,
                        a = xi * a_step
                    )
                    [r * cos(a), r * sin(a), -z + row_leng]
                ],
                [for(xi = row_range)
                    let(a = xi * a_step)
                    [ir * cos(a), ir * sin(a), -z + row_leng]
                ]
            )

    ];

    sweep(sections,  "HOLLOW");
}
nesdnuma commented 2 years ago

Thanks a lot, Justin!