discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Re-learning: some elementary queries

T
Terry
Mon, Oct 28, 2024 5:30 PM

Motivated by needing a small 3D print for an electronics project, I'm a
few days into relearning some of what little I once knew a year or three
ago.

I printed an 'end cover' using offset(). For further (re)learning I've
just coded an alternative using hull(), shown below. Not yet printed but
it looks OK.

CODE

// Designing gutter end cover Mon 28 Oct 2024

$fn=40;
module rounded_cover(x,y,z,r)
{
hull()
{
translate([r,r,0])
cylinder(h=z,r=r);
translate([x-r,r,0])
cylinder(h=z,r=r);
translate([x-r,y-r,0])
cylinder(h=z,r=r);
translate([r,y-r,0])
cylinder(h=z,r=r);
}
}

// Make two and use Difference

difference()
{
color("red")
rounded_cover(66.5,66.5,15,5);

translate([2,2,2])
color("blue")
rounded_cover(62.5,62.5,20,5);
}

Q1:
Any suggestions for other methods of improvememnts?

Q2:
If I use the disable modifier '%'
%color("red")
I expected to 'see through' the red part, so why do I get this instead?
https://www.dropbox.com/scl/fi/r9g54q9v09t0jthdodfhu/TransparencyQuery.jpg?rlkey=qfi2s8fjiucksa21fou55y5kf&raw=1

Q3:
Using the mouse wheel to zoom in/out almost never works. Sometimes
nothing, sometimes scrolls the editor, occasionally works if I click
another app and return. But does work consistently if I hide the editor.
Apparently long known bug. Or fixed for some but not me?
https://github.com/openscad/openscad/issues/4361

Terry, UK

Motivated by needing a small 3D print for an electronics project, I'm a few days into relearning some of what little I once knew a year or three ago. I printed an 'end cover' using offset(). For further (re)learning I've just coded an alternative using hull(), shown below. Not yet printed but it looks OK. CODE --------------- // Designing gutter end cover Mon 28 Oct 2024 $fn=40; module rounded_cover(x,y,z,r) { hull() { translate([r,r,0]) cylinder(h=z,r=r); translate([x-r,r,0]) cylinder(h=z,r=r); translate([x-r,y-r,0]) cylinder(h=z,r=r); translate([r,y-r,0]) cylinder(h=z,r=r); } } // Make two and use Difference difference() { color("red") rounded_cover(66.5,66.5,15,5); translate([2,2,2]) color("blue") rounded_cover(62.5,62.5,20,5); } --------------- Q1: Any suggestions for other methods of improvememnts? Q2: If I use the disable modifier '%' %color("red") I expected to 'see through' the red part, so why do I get this instead? https://www.dropbox.com/scl/fi/r9g54q9v09t0jthdodfhu/TransparencyQuery.jpg?rlkey=qfi2s8fjiucksa21fou55y5kf&raw=1 Q3: Using the mouse wheel to zoom in/out almost never works. Sometimes nothing, sometimes scrolls the editor, occasionally works if I click another app and return. But does work consistently if I hide the editor. Apparently long known bug. Or fixed for some but not me? https://github.com/openscad/openscad/issues/4361 Terry, UK
JB
Jordan Brown
Mon, Oct 28, 2024 6:58 PM

Review comments, other responses in a separate message.

It isn't clear whether you didn't indent, or if the indentation was just
lost in e-mail processing.  Always indent; it's critical for readability
in more complex projects.

If you ever start to set $fn globally, stop.  Use $fn only to create
regular polygons.  Instead use $fs and $fa; they will not produce silly
results for small or large circles.  Opinions vary on the exact values
to use, but $fa=3 and $fs=1 is a pretty good starting point.

Parameterizing the values (putting them into variables and calculating
one from another) seems more complex, but can often make things simpler
because you can make the relationships between the numbers more
obvious.  Note that in the example below I specify the outside size and
radius and the desired wall thickness, and calculate the inside
dimensions from that.

Carry around XYZ triples as arrays and refer to their components using
".x" notation; it can be simpler than using separate variables.

Look for commonality that you can wrap "for" loops around.  You're
placing the same cylinder four times, and you're translating x to r and
size-r and similarly y.  That's

for (cylX = [r, x-r], cylY = [r, y-r])
    translate([cylX, cylY,0])
    cylinder(...)

You have the radius on the inside corners the same as the radius on the
outside corners.  The result is that you have the corners a little
thicker than the rest. You want to use a radius that's smaller by the
desired thickness of the wall, changing the "5" in the second call to 3.

Here's my rewrite:

// Designing gutter end cover Mon 28 Oct 2024

$fa = 3;
$fs = 1;

oSize = [66.5, 66.5, 15];
oRadius = 5;
thickness = 2;
iSize = [ oSize.x - thickness*2, oSize.y - thickness*2, oSize.z ];
iRadius = oRadius - thickness;

module rounded_cover(size,r)
{
    hull()
    {
        for (x=[r, size.x-r], y=[r, size.y-r])
            translate([x,y,0])
            cylinder(h=size.z,r=r);
    }
}

// Make two and use Difference

difference()
{
    color("red")
        rounded_cover(oSize,oRadius);

    translate([2,2,2])
        color("blue")
        rounded_cover(iSize,iRadius);
}

You might look at BOSL2 https://github.com/BelfrySCAD/BOSL2/wiki.   It
has so many features that it can be a bit overwhelming, but if you like
curvy edges it can do them very easily.

include <BOSL2/std.scad>

$fa = 3;
$fs = 1;

oSize = [66.5, 66.5, 15];
oRadius = 5;
thickness = 2;
iSize = [ oSize.x - thickness*2, oSize.y - thickness*2, oSize.z ];
iRadius = oRadius - thickness;

difference() {
    color("red") cuboid(oSize, rounding=oRadius, edges="Z", anchor=BOTTOM);
    color("blue") translate([0,0,thickness]) cuboid(iSize, rounding=iRadius, edges="Z", anchor=BOTTOM);
}

Changing the edges="Z" to except=TOP will round the bottom corners too. 
Whether that's desirable on the inside depends on what this is mating
to.  (Also note that printing rounded bottom corners can be difficult;
see the "teardrop" parameter.)

There's probably a more-or-less straightforward way to round the top
edges too, at a smaller radius, but I'm not enough of a BOSL2 user to
know it without research.

Review comments, other responses in a separate message. It isn't clear whether you didn't indent, or if the indentation was just lost in e-mail processing.  Always indent; it's critical for readability in more complex projects. If you ever start to set $fn globally, stop.  Use $fn only to create regular polygons.  Instead use $fs and $fa; they will not produce silly results for small or large circles.  Opinions vary on the exact values to use, but $fa=3 and $fs=1 is a pretty good starting point. Parameterizing the values (putting them into variables and calculating one from another) seems more complex, but can often make things simpler because you can make the relationships between the numbers more obvious.  Note that in the example below I specify the outside size and radius and the desired wall thickness, and calculate the inside dimensions from that. Carry around XYZ triples as arrays and refer to their components using ".x" notation; it can be simpler than using separate variables. Look for commonality that you can wrap "for" loops around.  You're placing the same cylinder four times, and you're translating x to r and size-r and similarly y.  That's for (cylX = [r, x-r], cylY = [r, y-r]) translate([cylX, cylY,0]) cylinder(...) You have the radius on the inside corners the same as the radius on the outside corners.  The result is that you have the corners a little thicker than the rest. You want to use a radius that's smaller by the desired thickness of the wall, changing the "5" in the second call to 3. Here's my rewrite: // Designing gutter end cover Mon 28 Oct 2024 $fa = 3; $fs = 1; oSize = [66.5, 66.5, 15]; oRadius = 5; thickness = 2; iSize = [ oSize.x - thickness*2, oSize.y - thickness*2, oSize.z ]; iRadius = oRadius - thickness; module rounded_cover(size,r) { hull() { for (x=[r, size.x-r], y=[r, size.y-r]) translate([x,y,0]) cylinder(h=size.z,r=r); } } // Make two and use Difference difference() { color("red") rounded_cover(oSize,oRadius); translate([2,2,2]) color("blue") rounded_cover(iSize,iRadius); } You might look at BOSL2 <https://github.com/BelfrySCAD/BOSL2/wiki>.   It has so many features that it can be a bit overwhelming, but if you like curvy edges it can do them very easily. include <BOSL2/std.scad> $fa = 3; $fs = 1; oSize = [66.5, 66.5, 15]; oRadius = 5; thickness = 2; iSize = [ oSize.x - thickness*2, oSize.y - thickness*2, oSize.z ]; iRadius = oRadius - thickness; difference() { color("red") cuboid(oSize, rounding=oRadius, edges="Z", anchor=BOTTOM); color("blue") translate([0,0,thickness]) cuboid(iSize, rounding=iRadius, edges="Z", anchor=BOTTOM); } Changing the edges="Z" to except=TOP will round the bottom corners too.  Whether that's desirable on the inside depends on what this is mating to.  (Also note that printing rounded bottom corners can be difficult; see the "teardrop" parameter.) There's probably a more-or-less straightforward way to round the top edges too, at a smaller radius, but I'm not enough of a BOSL2 user to know it without research.
JB
Jordan Brown
Mon, Oct 28, 2024 7:01 PM

On 10/28/2024 10:30 AM, Terry via Discuss wrote:

Q2:
If I use the disable modifier '%'
%color("red")
I expected to 'see through' the red part, so why do I get this instead?
https://www.dropbox.com/scl/fi/r9g54q9v09t0jthdodfhu/TransparencyQuery.jpg?rlkey=qfi2s8fjiucksa21fou55y5kf&raw=1

No idea.  Difference is a bit magic, color is a bit magic, and
transparency is very magic, so it's not at all surprising that they
interact poorly.

Q3:
Using the mouse wheel to zoom in/out almost never works. Sometimes
nothing, sometimes scrolls the editor, occasionally works if I click
another app and return. But does work consistently if I hide the editor.
Apparently long known bug. Or fixed for some but not me?
https://github.com/openscad/openscad/issues/4361

What platform?  Always works for me on Windows.  Note that the mouse
cursor has to be in the correct pane.

On 10/28/2024 10:30 AM, Terry via Discuss wrote: > Q2: > If I use the disable modifier '%' > %color("red") > I expected to 'see through' the red part, so why do I get this instead? > https://www.dropbox.com/scl/fi/r9g54q9v09t0jthdodfhu/TransparencyQuery.jpg?rlkey=qfi2s8fjiucksa21fou55y5kf&raw=1 No idea.  Difference is a bit magic, color is a bit magic, and transparency is very magic, so it's not at all surprising that they interact poorly. > Q3: > Using the mouse wheel to zoom in/out almost never works. Sometimes > nothing, sometimes scrolls the editor, occasionally works if I click > another app and return. But does work consistently if I hide the editor. > Apparently long known bug. Or fixed for some but not me? > https://github.com/openscad/openscad/issues/4361 What platform?  Always works for me on Windows.  Note that the mouse cursor has to be in the correct pane.
NH
nop head
Mon, Oct 28, 2024 7:17 PM

color overides the % operator. If you want a transparent colour you need to
pass an alpha parameter to colour.

The % operator also removes the object from the F6 render so you might need
both.

On Mon, 28 Oct 2024 at 19:02, Jordan Brown via Discuss <
discuss@lists.openscad.org> wrote:

On 10/28/2024 10:30 AM, Terry via Discuss wrote:

Q2:
If I use the disable modifier '%'
%color("red")
I expected to 'see through' the red part, so why do I get this instead?https://www.dropbox.com/scl/fi/r9g54q9v09t0jthdodfhu/TransparencyQuery.jpg?rlkey=qfi2s8fjiucksa21fou55y5kf&raw=1

No idea.  Difference is a bit magic, color is a bit magic, and
transparency is very magic, so it's not at all surprising that they
interact poorly.

Q3:
Using the mouse wheel to zoom in/out almost never works. Sometimes
nothing, sometimes scrolls the editor, occasionally works if I click
another app and return. But does work consistently if I hide the editor.
Apparently long known bug. Or fixed for some but not me?https://github.com/openscad/openscad/issues/4361

What platform?  Always works for me on Windows.  Note that the mouse
cursor has to be in the correct pane.


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

color overides the % operator. If you want a transparent colour you need to pass an alpha parameter to colour. The % operator also removes the object from the F6 render so you might need both. On Mon, 28 Oct 2024 at 19:02, Jordan Brown via Discuss < discuss@lists.openscad.org> wrote: > On 10/28/2024 10:30 AM, Terry via Discuss wrote: > > Q2: > If I use the disable modifier '%' > %color("red") > I expected to 'see through' the red part, so why do I get this instead?https://www.dropbox.com/scl/fi/r9g54q9v09t0jthdodfhu/TransparencyQuery.jpg?rlkey=qfi2s8fjiucksa21fou55y5kf&raw=1 > > > No idea. Difference is a bit magic, color is a bit magic, and > transparency is very magic, so it's not at all surprising that they > interact poorly. > > Q3: > Using the mouse wheel to zoom in/out almost never works. Sometimes > nothing, sometimes scrolls the editor, occasionally works if I click > another app and return. But does work consistently if I hide the editor. > Apparently long known bug. Or fixed for some but not me?https://github.com/openscad/openscad/issues/4361 > > > What platform? Always works for me on Windows. Note that the mouse > cursor has to be in the correct pane. > > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
AM
Adrian Mariano
Mon, Oct 28, 2024 7:58 PM

If you want to round edges of a cube with different roundings in BOSL2 you
need to use edge_profile() to to do that, so something like:

diff()
cuboid(10,rounding=2,edges=BOT)
edge_profile(TOP) mask2d_roundover(r=4);

where one rounding is applied within cuboid() and the other with edge
profile.  Or you can apply many roundings of different edge sets with
multiple edge_profile invocations.  (Actually the edge profiles can be
anything, not just roundings.  See also edge_profile_asym() for handling
the case when the edge profile is asymmetric across the plane that bisects
the edge corner.)

On Mon, Oct 28, 2024 at 3:02 PM Jordan Brown via Discuss <
discuss@lists.openscad.org> wrote:

On 10/28/2024 10:30 AM, Terry via Discuss wrote:

Q2:
If I use the disable modifier '%'
%color("red")
I expected to 'see through' the red part, so why do I get this instead?https://www.dropbox.com/scl/fi/r9g54q9v09t0jthdodfhu/TransparencyQuery.jpg?rlkey=qfi2s8fjiucksa21fou55y5kf&raw=1

No idea.  Difference is a bit magic, color is a bit magic, and
transparency is very magic, so it's not at all surprising that they
interact poorly.

Q3:
Using the mouse wheel to zoom in/out almost never works. Sometimes
nothing, sometimes scrolls the editor, occasionally works if I click
another app and return. But does work consistently if I hide the editor.
Apparently long known bug. Or fixed for some but not me?https://github.com/openscad/openscad/issues/4361

What platform?  Always works for me on Windows.  Note that the mouse
cursor has to be in the correct pane.


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

If you want to round edges of a cube with different roundings in BOSL2 you need to use edge_profile() to to do that, so something like: diff() cuboid(10,rounding=2,edges=BOT) edge_profile(TOP) mask2d_roundover(r=4); where one rounding is applied within cuboid() and the other with edge profile. Or you can apply many roundings of different edge sets with multiple edge_profile invocations. (Actually the edge profiles can be anything, not just roundings. See also edge_profile_asym() for handling the case when the edge profile is asymmetric across the plane that bisects the edge corner.) On Mon, Oct 28, 2024 at 3:02 PM Jordan Brown via Discuss < discuss@lists.openscad.org> wrote: > On 10/28/2024 10:30 AM, Terry via Discuss wrote: > > Q2: > If I use the disable modifier '%' > %color("red") > I expected to 'see through' the red part, so why do I get this instead?https://www.dropbox.com/scl/fi/r9g54q9v09t0jthdodfhu/TransparencyQuery.jpg?rlkey=qfi2s8fjiucksa21fou55y5kf&raw=1 > > > No idea. Difference is a bit magic, color is a bit magic, and > transparency is very magic, so it's not at all surprising that they > interact poorly. > > Q3: > Using the mouse wheel to zoom in/out almost never works. Sometimes > nothing, sometimes scrolls the editor, occasionally works if I click > another app and return. But does work consistently if I hide the editor. > Apparently long known bug. Or fixed for some but not me?https://github.com/openscad/openscad/issues/4361 > > > What platform? Always works for me on Windows. Note that the mouse > cursor has to be in the correct pane. > > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
T
Terry
Tue, Oct 29, 2024 2:52 PM

Thanks Adrian. I'll get the basics re-learned, and then maybe tackle
BOSL2.

On Mon, 28 Oct 2024 15:58:08 -0400, you wrote:

If you want to round edges of a cube with different roundings in BOSL2 you
need to use edge_profile() to to do that, so something like:

diff()
cuboid(10,rounding=2,edges=BOT)
edge_profile(TOP) mask2d_roundover(r=4);

where one rounding is applied within cuboid() and the other with edge
profile.  Or you can apply many roundings of different edge sets with
multiple edge_profile invocations.  (Actually the edge profiles can be
anything, not just roundings.  See also edge_profile_asym() for handling
the case when the edge profile is asymmetric across the plane that bisects
the edge corner.)

On Mon, Oct 28, 2024 at 3:02?PM Jordan Brown via Discuss <
discuss@lists.openscad.org> wrote:

On 10/28/2024 10:30 AM, Terry via Discuss wrote:

Q2:
If I use the disable modifier '%'
%color("red")
I expected to 'see through' the red part, so why do I get this instead?https://www.dropbox.com/scl/fi/r9g54q9v09t0jthdodfhu/TransparencyQuery.jpg?rlkey=qfi2s8fjiucksa21fou55y5kf&raw=1

No idea.  Difference is a bit magic, color is a bit magic, and
transparency is very magic, so it's not at all surprising that they
interact poorly.

Q3:
Using the mouse wheel to zoom in/out almost never works. Sometimes
nothing, sometimes scrolls the editor, occasionally works if I click
another app and return. But does work consistently if I hide the editor.
Apparently long known bug. Or fixed for some but not me?https://github.com/openscad/openscad/issues/4361

What platform?  Always works for me on Windows.  Note that the mouse
cursor has to be in the correct pane.


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

Thanks Adrian. I'll get the basics re-learned, and then maybe tackle BOSL2. On Mon, 28 Oct 2024 15:58:08 -0400, you wrote: >If you want to round edges of a cube with different roundings in BOSL2 you >need to use edge_profile() to to do that, so something like: > >diff() >cuboid(10,rounding=2,edges=BOT) > edge_profile(TOP) mask2d_roundover(r=4); > >where one rounding is applied within cuboid() and the other with edge >profile. Or you can apply many roundings of different edge sets with >multiple edge_profile invocations. (Actually the edge profiles can be >anything, not just roundings. See also edge_profile_asym() for handling >the case when the edge profile is asymmetric across the plane that bisects >the edge corner.) > >On Mon, Oct 28, 2024 at 3:02?PM Jordan Brown via Discuss < >discuss@lists.openscad.org> wrote: > >> On 10/28/2024 10:30 AM, Terry via Discuss wrote: >> >> Q2: >> If I use the disable modifier '%' >> %color("red") >> I expected to 'see through' the red part, so why do I get this instead?https://www.dropbox.com/scl/fi/r9g54q9v09t0jthdodfhu/TransparencyQuery.jpg?rlkey=qfi2s8fjiucksa21fou55y5kf&raw=1 >> >> >> No idea. Difference is a bit magic, color is a bit magic, and >> transparency is very magic, so it's not at all surprising that they >> interact poorly. >> >> Q3: >> Using the mouse wheel to zoom in/out almost never works. Sometimes >> nothing, sometimes scrolls the editor, occasionally works if I click >> another app and return. But does work consistently if I hide the editor. >> Apparently long known bug. Or fixed for some but not me?https://github.com/openscad/openscad/issues/4361 >> >> >> What platform? Always works for me on Windows. Note that the mouse >> cursor has to be in the correct pane. >> >> _______________________________________________ >> OpenSCAD mailing list >> To unsubscribe send an email to discuss-leave@lists.openscad.org >>
T
Terry
Tue, Oct 29, 2024 3:22 PM

Thanks, that does it.

%color("red", 0.5)

====================

On Mon, 28 Oct 2024 19:17:27 +0000, you wrote:

color overides the % operator. If you want a transparent colour you need to
pass an alpha parameter to colour.

The % operator also removes the object from the F6 render so you might need
both.

On Mon, 28 Oct 2024 at 19:02, Jordan Brown via Discuss <
discuss@lists.openscad.org> wrote:

On 10/28/2024 10:30 AM, Terry via Discuss wrote:

Q2:
If I use the disable modifier '%'
%color("red")
I expected to 'see through' the red part, so why do I get this instead?https://www.dropbox.com/scl/fi/r9g54q9v09t0jthdodfhu/TransparencyQuery.jpg?rlkey=qfi2s8fjiucksa21fou55y5kf&raw=1

No idea.  Difference is a bit magic, color is a bit magic, and
transparency is very magic, so it's not at all surprising that they
interact poorly.

Q3:
Using the mouse wheel to zoom in/out almost never works. Sometimes
nothing, sometimes scrolls the editor, occasionally works if I click
another app and return. But does work consistently if I hide the editor.
Apparently long known bug. Or fixed for some but not me?https://github.com/openscad/openscad/issues/4361

What platform?  Always works for me on Windows.  Note that the mouse
cursor has to be in the correct pane.


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

Thanks, that does it. %color("red", 0.5) ==================== On Mon, 28 Oct 2024 19:17:27 +0000, you wrote: >color overides the % operator. If you want a transparent colour you need to >pass an alpha parameter to colour. > >The % operator also removes the object from the F6 render so you might need >both. > >On Mon, 28 Oct 2024 at 19:02, Jordan Brown via Discuss < >discuss@lists.openscad.org> wrote: > >> On 10/28/2024 10:30 AM, Terry via Discuss wrote: >> >> Q2: >> If I use the disable modifier '%' >> %color("red") >> I expected to 'see through' the red part, so why do I get this instead?https://www.dropbox.com/scl/fi/r9g54q9v09t0jthdodfhu/TransparencyQuery.jpg?rlkey=qfi2s8fjiucksa21fou55y5kf&raw=1 >> >> >> No idea. Difference is a bit magic, color is a bit magic, and >> transparency is very magic, so it's not at all surprising that they >> interact poorly. >> >> Q3: >> Using the mouse wheel to zoom in/out almost never works. Sometimes >> nothing, sometimes scrolls the editor, occasionally works if I click >> another app and return. But does work consistently if I hide the editor. >> Apparently long known bug. Or fixed for some but not me?https://github.com/openscad/openscad/issues/4361 >> >> >> What platform? Always works for me on Windows. Note that the mouse >> cursor has to be in the correct pane. >> >> _______________________________________________ >> OpenSCAD mailing list >> To unsubscribe send an email to discuss-leave@lists.openscad.org >>