discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

r1 and r2

RW
Rogier Wolff
Wed, Mar 16, 2022 12:32 PM

On Wed, Mar 16, 2022 at 08:03:54AM -0400, jon wrote:

Easy enough to roll your own CubeCXY() which centers in XY.

module CubeCXY(v) translate([-v[0]/2, -v[1]/2, 0]) cube (v);

--
** R.E.Wolff@BitWizard.nl ** https://www.BitWizard.nl/ ** +31-15-2049110 **
**    Delftechpark 11 2628 XJ  Delft, The Netherlands.  KVK: 27239233    **
f equals m times a. When your f is steady, and your m is going down
your a is going up.  -- Chris Hadfield about flying up the space shuttle.

On Wed, Mar 16, 2022 at 08:03:54AM -0400, jon wrote: > Easy enough to roll your own CubeCXY() which centers in XY. module CubeCXY(v) translate([-v[0]/2, -v[1]/2, 0]) cube (v); -- ** R.E.Wolff@BitWizard.nl ** https://www.BitWizard.nl/ ** +31-15-2049110 ** ** Delftechpark 11 2628 XJ Delft, The Netherlands. KVK: 27239233 ** f equals m times a. When your f is steady, and your m is going down your a is going up. -- Chris Hadfield about flying up the space shuttle.
RW
Raymond West
Wed, Mar 16, 2022 2:07 PM

too simple and straightforward...

a bit more involved

module cubec(x,y,z)
{
    scale ([x,y,z])
    rotate([0,0,45])
    linear_extrude(1)
    circle (sqrt(2)/2,$fn=4);
}

cubec(80,40,50);

On 16/03/2022 12:32, Rogier Wolff wrote:

On Wed, Mar 16, 2022 at 08:03:54AM -0400, jon wrote:

Easy enough to roll your own CubeCXY() which centers in XY.
module CubeCXY(v) translate([-v[0]/2, -v[1]/2, 0]) cube (v);

too simple and straightforward... a bit more involved module cubec(x,y,z) {     scale ([x,y,z])     rotate([0,0,45])     linear_extrude(1)     circle (sqrt(2)/2,$fn=4); } cubec(80,40,50); On 16/03/2022 12:32, Rogier Wolff wrote: > On Wed, Mar 16, 2022 at 08:03:54AM -0400, jon wrote: >> Easy enough to roll your own CubeCXY() which centers in XY. > module CubeCXY(v) translate([-v[0]/2, -v[1]/2, 0]) cube (v); >
J
jon
Wed, Mar 16, 2022 2:42 PM

LOL!  Yes!  So many ways to approach this simple construct!

On 3/16/2022 10:07 AM, Raymond West wrote:

too simple and straightforward...

a bit more involved

module cubec(x,y,z)
{
    scale ([x,y,z])
    rotate([0,0,45])
    linear_extrude(1)
    circle (sqrt(2)/2,$fn=4);
}

cubec(80,40,50);

On 16/03/2022 12:32, Rogier Wolff wrote:

On Wed, Mar 16, 2022 at 08:03:54AM -0400, jon wrote:

Easy enough to roll your own CubeCXY() which centers in XY.
module CubeCXY(v) translate([-v[0]/2, -v[1]/2, 0]) cube (v);

LOL!  Yes!  So many ways to approach this simple construct! On 3/16/2022 10:07 AM, Raymond West wrote: > too simple and straightforward... > > a bit more involved > > module cubec(x,y,z) > { >     scale ([x,y,z]) >     rotate([0,0,45]) >     linear_extrude(1) >     circle (sqrt(2)/2,$fn=4); > } > > cubec(80,40,50); > > > On 16/03/2022 12:32, Rogier Wolff wrote: >> On Wed, Mar 16, 2022 at 08:03:54AM -0400, jon wrote: >>> Easy enough to roll your own CubeCXY() which centers in XY. >> module CubeCXY(v) translate([-v[0]/2, -v[1]/2, 0]) cube (v); >>
JB
Jordan Brown
Wed, Mar 16, 2022 3:08 PM

On 3/15/2022 9:26 PM, David Schooley wrote:

The difference between how cubes are handled vs.cylinders has always been interesting. I have a lot of code that is more of a mess than necessary because cubes don’t center on the X-Y plane but cylinders do. I think what OpenSCAD does is correct, but a “centerxy” parameter for cubes would be a good thing.

My point is that by default they all start at Z=0 and expand into +Z
from there, which helps me to think of the bottom as the "first" face.

But I agree that it would be good to have more options.  One of my
library modules is jcube(), which builds a cube and then justifies it as
specified by a vec3.  In each axis, -1 justifies the cube on the
negative side of the origin, 0 centers, and +1 justifies on the positive
side.  Thus, for instance, jcube(dims=[1,1,1], j=[0,0,-1]) makes a cube
that is centered in X and Y, and extends down from the origin in Z.  I
use jcube() all the time; it makes things significantly simpler. 
There's been some discussion of having the standard center argument take
a similar vec3, but it's never gone anywhere.

I also have a more general justify() that accepts a bounding box for its
children and a justification parameter, and justifies its children.

I've been thinking about a jcircle(), but that's trickier because you
have to decide whether you want to align based on a theoretical circle,
or on the actual polygon generated.  They're only the same for $fn being
a multiple of four.  (And it's worse for spheres, where there's no $fn
that puts vertices on all three axes.)

On 3/15/2022 9:26 PM, David Schooley wrote: > The difference between how cubes are handled vs.cylinders has always been interesting. I have a lot of code that is more of a mess than necessary because cubes don’t center on the X-Y plane but cylinders do. I think what OpenSCAD does is correct, but a “centerxy” parameter for cubes would be a good thing. My point is that by default they all start at Z=0 and expand into +Z from there, which helps me to think of the bottom as the "first" face. But I agree that it would be good to have more options.  One of my library modules is jcube(), which builds a cube and then justifies it as specified by a vec3.  In each axis, -1 justifies the cube on the negative side of the origin, 0 centers, and +1 justifies on the positive side.  Thus, for instance, jcube(dims=[1,1,1], j=[0,0,-1]) makes a cube that is centered in X and Y, and extends down from the origin in Z.  I use jcube() all the time; it makes things significantly simpler.  There's been some discussion of having the standard center argument take a similar vec3, but it's never gone anywhere. I also have a more general justify() that accepts a bounding box for its children and a justification parameter, and justifies its children. I've been thinking about a jcircle(), but that's trickier because you have to decide whether you want to align based on a theoretical circle, or on the actual polygon generated.  They're only the same for $fn being a multiple of four.  (And it's worse for spheres, where there's no $fn that puts vertices on all three axes.)
NH
nop head
Wed, Mar 16, 2022 3:13 PM

Not good to have the outer dimensions multiples of an irrational even when
the cube is aligned with the axes and it has rational dimensions.

I override sphere() to have points on all six half axes by making it a
rotate_extrude of a semi circle. Otherwise anything created with hulls of
spheres has incorrect dimensions.

On Wed, 16 Mar 2022 at 14:49, jon jon@jonbondy.com wrote:

LOL!  Yes!  So many ways to approach this simple construct!

On 3/16/2022 10:07 AM, Raymond West wrote:

too simple and straightforward...

a bit more involved

module cubec(x,y,z)
{
scale ([x,y,z])
rotate([0,0,45])
linear_extrude(1)
circle (sqrt(2)/2,$fn=4);
}

cubec(80,40,50);

On 16/03/2022 12:32, Rogier Wolff wrote:

On Wed, Mar 16, 2022 at 08:03:54AM -0400, jon wrote:

Easy enough to roll your own CubeCXY() which centers in XY.

module CubeCXY(v) translate([-v[0]/2, -v[1]/2, 0]) cube (v);


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

Not good to have the outer dimensions multiples of an irrational even when the cube is aligned with the axes and it has rational dimensions. I override sphere() to have points on all six half axes by making it a rotate_extrude of a semi circle. Otherwise anything created with hulls of spheres has incorrect dimensions. On Wed, 16 Mar 2022 at 14:49, jon <jon@jonbondy.com> wrote: > LOL! Yes! So many ways to approach this simple construct! > > On 3/16/2022 10:07 AM, Raymond West wrote: > > too simple and straightforward... > > > > a bit more involved > > > > module cubec(x,y,z) > > { > > scale ([x,y,z]) > > rotate([0,0,45]) > > linear_extrude(1) > > circle (sqrt(2)/2,$fn=4); > > } > > > > cubec(80,40,50); > > > > > > On 16/03/2022 12:32, Rogier Wolff wrote: > >> On Wed, Mar 16, 2022 at 08:03:54AM -0400, jon wrote: > >>> Easy enough to roll your own CubeCXY() which centers in XY. > >> module CubeCXY(v) translate([-v[0]/2, -v[1]/2, 0]) cube (v); > >> > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
LM
Leonard Martin Struttmann
Wed, Mar 16, 2022 3:16 PM

Just curious, how do you make the semicircle?

On Wed, Mar 16, 2022, 10:14 nop head nop.head@gmail.com wrote:

Not good to have the outer dimensions multiples of an irrational even when
the cube is aligned with the axes and it has rational dimensions.

I override sphere() to have points on all six half axes by making it a
rotate_extrude of a semi circle. Otherwise anything created with hulls of
spheres has incorrect dimensions.

On Wed, 16 Mar 2022 at 14:49, jon jon@jonbondy.com wrote:

LOL!  Yes!  So many ways to approach this simple construct!

On 3/16/2022 10:07 AM, Raymond West wrote:

too simple and straightforward...

a bit more involved

module cubec(x,y,z)
{
scale ([x,y,z])
rotate([0,0,45])
linear_extrude(1)
circle (sqrt(2)/2,$fn=4);
}

cubec(80,40,50);

On 16/03/2022 12:32, Rogier Wolff wrote:

On Wed, Mar 16, 2022 at 08:03:54AM -0400, jon wrote:

Easy enough to roll your own CubeCXY() which centers in XY.

module CubeCXY(v) translate([-v[0]/2, -v[1]/2, 0]) cube (v);


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


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

Just curious, how do you make the semicircle? On Wed, Mar 16, 2022, 10:14 nop head <nop.head@gmail.com> wrote: > Not good to have the outer dimensions multiples of an irrational even when > the cube is aligned with the axes and it has rational dimensions. > > I override sphere() to have points on all six half axes by making it a > rotate_extrude of a semi circle. Otherwise anything created with hulls of > spheres has incorrect dimensions. > > On Wed, 16 Mar 2022 at 14:49, jon <jon@jonbondy.com> wrote: > >> LOL! Yes! So many ways to approach this simple construct! >> >> On 3/16/2022 10:07 AM, Raymond West wrote: >> > too simple and straightforward... >> > >> > a bit more involved >> > >> > module cubec(x,y,z) >> > { >> > scale ([x,y,z]) >> > rotate([0,0,45]) >> > linear_extrude(1) >> > circle (sqrt(2)/2,$fn=4); >> > } >> > >> > cubec(80,40,50); >> > >> > >> > On 16/03/2022 12:32, Rogier Wolff wrote: >> >> On Wed, Mar 16, 2022 at 08:03:54AM -0400, jon wrote: >> >>> Easy enough to roll your own CubeCXY() which centers in XY. >> >> module CubeCXY(v) translate([-v[0]/2, -v[1]/2, 0]) cube (v); >> >> >> _______________________________________________ >> OpenSCAD mailing list >> To unsubscribe send an email to discuss-leave@lists.openscad.org >> > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
NH
nop head
Wed, Mar 16, 2022 4:49 PM

function r2sides(r) = $fn ? $fn : ceil(max(min(360/ $fa, r * 2 * PI / $fs),
5));    //! Replicates the OpenSCAD logic to calculate the number of sides
from the radius
function r2sides4n(r) = floor((r2sides(r) + 3) / 4) * 4;
//! Round up the number of sides to a multiple of 4 to ensure
points land on all axes

module circle4n(r, d = undef) {                    //! Circle with
multiple of 4 vertices
R = is_undef(d) ? r : d / 2;
circle(R, $fn = r2sides4n(R));
}

module semi_circle(r, d = undef)                    //! A semi circle in
the positive Y domain
intersection() {
R = is_undef(d) ? r : d / 2;
circle4n(R);

    sq = R + 1;
    translate([-sq, 0])
        square([2 * sq, sq]);
}

//! Redefines sphere() to always have a vertex on all six half axes I.e.
vertices at the poles and the equator and $fn a multiple of four.
//! This ensures hull and minkowski results have the correct dimensions
when spheres are placed at the corners.

module sphere(r = 1, d = undef) {                  //! Override sphere
so that has vertices on all three axes. Has the advantage of giving correct
dimensions when hulled
R = is_undef(d) ? r : d / 2;
rotate_extrude($fn = r2sides4n(R))
rotate(-90)
semi_circle(R);
}

On Wed, 16 Mar 2022 at 15:16, Leonard Martin Struttmann <
lenstruttmann@gmail.com> wrote:

Just curious, how do you make the semicircle?

On Wed, Mar 16, 2022, 10:14 nop head nop.head@gmail.com wrote:

Not good to have the outer dimensions multiples of an irrational even
when the cube is aligned with the axes and it has rational dimensions.

I override sphere() to have points on all six half axes by making it a
rotate_extrude of a semi circle. Otherwise anything created with hulls of
spheres has incorrect dimensions.

On Wed, 16 Mar 2022 at 14:49, jon jon@jonbondy.com wrote:

LOL!  Yes!  So many ways to approach this simple construct!

On 3/16/2022 10:07 AM, Raymond West wrote:

too simple and straightforward...

a bit more involved

module cubec(x,y,z)
{
scale ([x,y,z])
rotate([0,0,45])
linear_extrude(1)
circle (sqrt(2)/2,$fn=4);
}

cubec(80,40,50);

On 16/03/2022 12:32, Rogier Wolff wrote:

On Wed, Mar 16, 2022 at 08:03:54AM -0400, jon wrote:

Easy enough to roll your own CubeCXY() which centers in XY.

module CubeCXY(v) translate([-v[0]/2, -v[1]/2, 0]) cube (v);


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


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


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

function r2sides(r) = $fn ? $fn : ceil(max(min(360/ $fa, r * 2 * PI / $fs), 5)); //! Replicates the OpenSCAD logic to calculate the number of sides from the radius function r2sides4n(r) = floor((r2sides(r) + 3) / 4) * 4; //! Round up the number of sides to a multiple of 4 to ensure points land on all axes module circle4n(r, d = undef) { //! Circle with multiple of 4 vertices R = is_undef(d) ? r : d / 2; circle(R, $fn = r2sides4n(R)); } module semi_circle(r, d = undef) //! A semi circle in the positive Y domain intersection() { R = is_undef(d) ? r : d / 2; circle4n(R); sq = R + 1; translate([-sq, 0]) square([2 * sq, sq]); } //! Redefines `sphere()` to always have a vertex on all six half axes I.e. vertices at the poles and the equator and `$fn` a multiple of four. //! This ensures `hull` and `minkowski` results have the correct dimensions when spheres are placed at the corners. module sphere(r = 1, d = undef) { //! Override `sphere` so that has vertices on all three axes. Has the advantage of giving correct dimensions when hulled R = is_undef(d) ? r : d / 2; rotate_extrude($fn = r2sides4n(R)) rotate(-90) semi_circle(R); } On Wed, 16 Mar 2022 at 15:16, Leonard Martin Struttmann < lenstruttmann@gmail.com> wrote: > Just curious, how do you make the semicircle? > > On Wed, Mar 16, 2022, 10:14 nop head <nop.head@gmail.com> wrote: > >> Not good to have the outer dimensions multiples of an irrational even >> when the cube is aligned with the axes and it has rational dimensions. >> >> I override sphere() to have points on all six half axes by making it a >> rotate_extrude of a semi circle. Otherwise anything created with hulls of >> spheres has incorrect dimensions. >> >> On Wed, 16 Mar 2022 at 14:49, jon <jon@jonbondy.com> wrote: >> >>> LOL! Yes! So many ways to approach this simple construct! >>> >>> On 3/16/2022 10:07 AM, Raymond West wrote: >>> > too simple and straightforward... >>> > >>> > a bit more involved >>> > >>> > module cubec(x,y,z) >>> > { >>> > scale ([x,y,z]) >>> > rotate([0,0,45]) >>> > linear_extrude(1) >>> > circle (sqrt(2)/2,$fn=4); >>> > } >>> > >>> > cubec(80,40,50); >>> > >>> > >>> > On 16/03/2022 12:32, Rogier Wolff wrote: >>> >> On Wed, Mar 16, 2022 at 08:03:54AM -0400, jon wrote: >>> >>> Easy enough to roll your own CubeCXY() which centers in XY. >>> >> module CubeCXY(v) translate([-v[0]/2, -v[1]/2, 0]) cube (v); >>> >> >>> _______________________________________________ >>> OpenSCAD mailing list >>> To unsubscribe send an email to discuss-leave@lists.openscad.org >>> >> _______________________________________________ >> OpenSCAD mailing list >> To unsubscribe send an email to discuss-leave@lists.openscad.org >> > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
AM
Adrian Mariano
Wed, Mar 16, 2022 8:37 PM

There is of course the BOSL2 solution, which provides similar flexibility, e.g.

cube(10, anchor=[0,0,-1]);  // cube with center of bottom face at the origin
cube(10,anchor=BOTTOM); // equivalent to above
cube(10,anchor=[1,1,0]);  // cube with its (1,1) vertical edge
centered on the origin
cube(10,anchor=BACK+RIGHT);  // equivalent to above

And so on.

On Wed, Mar 16, 2022 at 11:09 AM Jordan Brown
openscad@jordan.maileater.net wrote:

On 3/15/2022 9:26 PM, David Schooley wrote:

The difference between how cubes are handled vs.cylinders has always been interesting. I have a lot of code that is more of a mess than necessary because cubes don’t center on the X-Y plane but cylinders do. I think what OpenSCAD does is correct, but a “centerxy” parameter for cubes would be a good thing.

My point is that by default they all start at Z=0 and expand into +Z from there, which helps me to think of the bottom as the "first" face.

But I agree that it would be good to have more options.  One of my library modules is jcube(), which builds a cube and then justifies it as specified by a vec3.  In each axis, -1 justifies the cube on the negative side of the origin, 0 centers, and +1 justifies on the positive side.  Thus, for instance, jcube(dims=[1,1,1], j=[0,0,-1]) makes a cube that is centered in X and Y, and extends down from the origin in Z.  I use jcube() all the time; it makes things significantly simpler.  There's been some discussion of having the standard center argument take a similar vec3, but it's never gone anywhere.

I also have a more general justify() that accepts a bounding box for its children and a justification parameter, and justifies its children.

I've been thinking about a jcircle(), but that's trickier because you have to decide whether you want to align based on a theoretical circle, or on the actual polygon generated.  They're only the same for $fn being a multiple of four.  (And it's worse for spheres, where there's no $fn that puts vertices on all three axes.)


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

There is of course the BOSL2 solution, which provides similar flexibility, e.g. cube(10, anchor=[0,0,-1]); // cube with center of bottom face at the origin cube(10,anchor=BOTTOM); // equivalent to above cube(10,anchor=[1,1,0]); // cube with its (1,1) vertical edge centered on the origin cube(10,anchor=BACK+RIGHT); // equivalent to above And so on. On Wed, Mar 16, 2022 at 11:09 AM Jordan Brown <openscad@jordan.maileater.net> wrote: > > On 3/15/2022 9:26 PM, David Schooley wrote: > > The difference between how cubes are handled vs.cylinders has always been interesting. I have a lot of code that is more of a mess than necessary because cubes don’t center on the X-Y plane but cylinders do. I think what OpenSCAD does is correct, but a “centerxy” parameter for cubes would be a good thing. > > > My point is that by default they all start at Z=0 and expand into +Z from there, which helps me to think of the bottom as the "first" face. > > But I agree that it would be good to have more options. One of my library modules is jcube(), which builds a cube and then justifies it as specified by a vec3. In each axis, -1 justifies the cube on the negative side of the origin, 0 centers, and +1 justifies on the positive side. Thus, for instance, jcube(dims=[1,1,1], j=[0,0,-1]) makes a cube that is centered in X and Y, and extends down from the origin in Z. I use jcube() all the time; it makes things significantly simpler. There's been some discussion of having the standard center argument take a similar vec3, but it's never gone anywhere. > > I also have a more general justify() that accepts a bounding box for its children and a justification parameter, and justifies its children. > > I've been thinking about a jcircle(), but that's trickier because you have to decide whether you want to align based on a theoretical circle, or on the actual polygon generated. They're only the same for $fn being a multiple of four. (And it's worse for spheres, where there's no $fn that puts vertices on all three axes.) > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org
DM
Douglas Miller
Thu, Mar 17, 2022 11:08 AM

On 3/16/2022 11:16 AM, Leonard Martin Struttmann wrote:

Just curious, how do you make the semicircle?

Just for fun, here's one way to do that:

projection() rotate_extrude(angle=180) square([10,0.001]); //
semicircle, radius 10, in positive y

On 3/16/2022 11:16 AM, Leonard Martin Struttmann wrote: > Just curious, how do you make the semicircle? > Just for fun, here's one way to do that: projection() rotate_extrude(angle=180) square([10,0.001]); // semicircle, radius 10, in positive y
DM
Douglas Miller
Thu, Mar 17, 2022 11:10 AM

Thank you! TIL...

I'm not sure how I managed to avoid knowing that, but thank you. That
will come in handy.

On 3/16/2022 8:19 AM, Torsten Paul wrote:

On 16.03.22 13:14, Douglas Miller wrote:

     DeltaZ = center ? -z/2 : 0;
     translate([0,0,DeltaZ]) linear_extrude(height=z)
square([x,y],true);

linear_extrude(height=z, center=center) square([x,y],true);

No need for translate(), linear_extrude() has a center
parameter too.

ciao,
  Torsten.

Thank you! TIL... I'm not sure how I managed to avoid knowing that, but thank you. That will come in handy. On 3/16/2022 8:19 AM, Torsten Paul wrote: > On 16.03.22 13:14, Douglas Miller wrote: >>      DeltaZ = center ? -z/2 : 0; >>      translate([0,0,DeltaZ]) linear_extrude(height=z) >> square([x,y],true); > > linear_extrude(height=z, center=center) square([x,y],true); > > No need for translate(), linear_extrude() has a center > parameter too. > > ciao, >   Torsten.