discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Problems with a linear extrude of a hull of four squares minus a circle

NH
nop head
Thu, Feb 24, 2022 3:17 PM

I have some simple code that worked with older versions of OpenSCAD but
doesn't work with OpenSCAD 2021.10.19.ci9029. I can't test later versions
because they don't run on Win7.

It uses a lot of library code but I can take the CSG that produces nothing
on the snapshot and paste it into an older version and it works.

This is the CSG:

color([0.745098, 0.647059, 0.529412, 1]) {
linear_extrude(height = 18, center = true, $fn = 0, $fa = 6, $fs = 0.25) {
group() {
group() {
group();
difference() {
group() {
group();
hull() {
multmatrix([[1, 0, 0, -150], [0, 1, 0, 304], [0, 0, 1, 0],
[0, 0, 0, 1]]) {
group() {
group() {
group() {
multmatrix([[1, 0, 0, 0.5], [0, 1, 0, -0.5], [0, 0,
1, 0], [0, 0, 0, 1]]) {
square(size = [1, 1], center = true);
}
}
}
}
}
multmatrix([[1, 0, 0, 150], [0, 1, 0, 304], [0, 0, 1, 0], [0,
0, 0, 1]]) {
multmatrix([[0, 1, 0, 0], [-1, 0, 0, 0], [0, 0, 1, 0], [0,
0, 0, 1]]) {
group() {
group() {
group() {
multmatrix([[1, 0, 0, 0.5], [0, 1, 0, -0.5], [0, 0,
1, 0], [0, 0, 0, 1]]) {
square(size = [1, 1], center = true);
}
}
}
}
}
}
multmatrix([[1, 0, 0, 150], [0, 1, 0, -304], [0, 0, 1, 0],
[0, 0, 0, 1]]) {
multmatrix([[-1, 0, 0, 0], [0, -1, 0, 0], [0, 0, 1, 0], [0,
0, 0, 1]]) {
group() {
group() {
group() {
multmatrix([[1, 0, 0, 0.5], [0, 1, 0, -0.5], [0, 0,
1, 0], [0, 0, 0, 1]]) {
square(size = [1, 1], center = true);
}
}
}
}
}
}
multmatrix([[1, 0, 0, -150], [0, 1, 0, -304], [0, 0, 1, 0],
[0, 0, 0, 1]]) {
multmatrix([[0, -1, 0, 0], [1, 0, 0, 0], [0, 0, 1, 0], [0,
0, 0, 1]]) {
group() {
group() {
group() {
multmatrix([[1, 0, 0, 0.5], [0, 1, 0, -0.5], [0, 0,
1, 0], [0, 0, 0, 1]]) {
square(size = [1, 1], center = true);
}
}
}
}
}
}
}
}
group() {
group() {
multmatrix([[1, 0, 0, -70], [0, 1, 0, -177.1], [0, 0, 1, 0],
[0, 0, 0, 1]]) {
group() {
group() {
group() {
group() {
circle($fn = 0, $fa = 6, $fs = 0.25, r = 38.0521);
}
}
}
}
}
}
}
}
}
}
}
}

It should produce this:

[image: image.png]

The 2D version looks correct but disappears when extruded. The sheet is
made by my sheet_2D()
https://github.com/nophead/NopSCADlib/blob/master/vitamins/sheet.scad#L61
module that makes sheets with square, rounded or chamfered corners. It only
fails when the corners are square, and it only fails when a hole is cut out
of it. So it seems to be a combination of difference, hull and linear
extrude.

The source that makes the 2D version of each side looks like this:

module side(side) {
dxf(side > 0 ? "rhs" : "lhs");

difference() {
    sheet_2D(sheet, side_depth, side_height);
    //square([side_depth, side_height], center = true);

    if(extraction)
        if(side > 0)
            translate([extractor_pos.y - (depth / 2 - side_depth / 2),

-side_height / 2 + extractor_pos.z, 0]) {
drill(33 / 2, h = 0);

                rotate(90)
                    extractor_screw_positions(false)
                         drill(screw_clearance_radius(M3_cap_screw), h

= 0);
}
else
translate([extractor_pos.y - (depth / 2 - side_depth / 2),
-side_height / 2 + inlet_z, 0])
drill(inlet_r, h = 0);
}
}

If I replace sheet_2D with a square it works, or if I have minute radii or
chamfers it works. It also works if I comment out the holes for one side or
the other. It only fails when both sides have holes, so I think it might be
something to do with if and groups() inside difference().

If somebody can test it with a later snapshot I will post a bug report if
it is still broken.

I have some simple code that worked with older versions of OpenSCAD but doesn't work with OpenSCAD 2021.10.19.ci9029. I can't test later versions because they don't run on Win7. It uses a lot of library code but I can take the CSG that produces nothing on the snapshot and paste it into an older version and it works. This is the CSG: color([0.745098, 0.647059, 0.529412, 1]) { linear_extrude(height = 18, center = true, $fn = 0, $fa = 6, $fs = 0.25) { group() { group() { group(); difference() { group() { group(); hull() { multmatrix([[1, 0, 0, -150], [0, 1, 0, 304], [0, 0, 1, 0], [0, 0, 0, 1]]) { group() { group() { group() { multmatrix([[1, 0, 0, 0.5], [0, 1, 0, -0.5], [0, 0, 1, 0], [0, 0, 0, 1]]) { square(size = [1, 1], center = true); } } } } } multmatrix([[1, 0, 0, 150], [0, 1, 0, 304], [0, 0, 1, 0], [0, 0, 0, 1]]) { multmatrix([[0, 1, 0, 0], [-1, 0, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { group() { group() { group() { multmatrix([[1, 0, 0, 0.5], [0, 1, 0, -0.5], [0, 0, 1, 0], [0, 0, 0, 1]]) { square(size = [1, 1], center = true); } } } } } } multmatrix([[1, 0, 0, 150], [0, 1, 0, -304], [0, 0, 1, 0], [0, 0, 0, 1]]) { multmatrix([[-1, 0, 0, 0], [0, -1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { group() { group() { group() { multmatrix([[1, 0, 0, 0.5], [0, 1, 0, -0.5], [0, 0, 1, 0], [0, 0, 0, 1]]) { square(size = [1, 1], center = true); } } } } } } multmatrix([[1, 0, 0, -150], [0, 1, 0, -304], [0, 0, 1, 0], [0, 0, 0, 1]]) { multmatrix([[0, -1, 0, 0], [1, 0, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { group() { group() { group() { multmatrix([[1, 0, 0, 0.5], [0, 1, 0, -0.5], [0, 0, 1, 0], [0, 0, 0, 1]]) { square(size = [1, 1], center = true); } } } } } } } } group() { group() { multmatrix([[1, 0, 0, -70], [0, 1, 0, -177.1], [0, 0, 1, 0], [0, 0, 0, 1]]) { group() { group() { group() { group() { circle($fn = 0, $fa = 6, $fs = 0.25, r = 38.0521); } } } } } } } } } } } } It should produce this: [image: image.png] The 2D version looks correct but disappears when extruded. The sheet is made by my sheet_2D() <https://github.com/nophead/NopSCADlib/blob/master/vitamins/sheet.scad#L61> module that makes sheets with square, rounded or chamfered corners. It only fails when the corners are square, and it only fails when a hole is cut out of it. So it seems to be a combination of difference, hull and linear extrude. The source that makes the 2D version of each side looks like this: module side(side) { dxf(side > 0 ? "rhs" : "lhs"); difference() { sheet_2D(sheet, side_depth, side_height); //square([side_depth, side_height], center = true); if(extraction) if(side > 0) translate([extractor_pos.y - (depth / 2 - side_depth / 2), -side_height / 2 + extractor_pos.z, 0]) { drill(33 / 2, h = 0); rotate(90) extractor_screw_positions(false) drill(screw_clearance_radius(M3_cap_screw), h = 0); } else translate([extractor_pos.y - (depth / 2 - side_depth / 2), -side_height / 2 + inlet_z, 0]) drill(inlet_r, h = 0); } } If I replace sheet_2D with a square it works, or if I have minute radii or chamfers it works. It also works if I comment out the holes for one side or the other. It only fails when both sides have holes, so I think it might be something to do with if and groups() inside difference(). If somebody can test it with a later snapshot I will post a bug report if it is still broken.
JB
Jordan Brown
Thu, Feb 24, 2022 3:40 PM

Works for me with 2022.02.23 on Windows 10.

Works for me with 2022.02.23 on Windows 10.
NH
nop head
Thu, Feb 24, 2022 4:00 PM

Thanks. Perhaps it is a bug that is already fixed.

On Thu, 24 Feb 2022 at 15:40, Jordan Brown openscad@jordan.maileater.net
wrote:

Works for me with 2022.02.23 on Windows 10.

Thanks. Perhaps it is a bug that is already fixed. On Thu, 24 Feb 2022 at 15:40, Jordan Brown <openscad@jordan.maileater.net> wrote: > Works for me with 2022.02.23 on Windows 10. > >