Learning how to use OpenSCAD

classic Classic list List threaded Threaded
32 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Learning how to use OpenSCAD

adrianv
I've been using OpenSCAD for a while and lately as I've run across some more
sophisticated code examples, I really started to wonder: how does one learn
to use this tool?  The reference manual doesn't really give enough examples
and explanations of how to use OpenSCAD.  Are there any really complete
tutorials that explain everything?  

It seems like a complete explanation would also include a description of
libraries that are available, what exactly they can (and cannot) do, and how
to use them.  I found a list of libraries, but it's difficult to determine
what libraries actually can do.  And it's unclear how stable or "accepted"
various libraries are.  Are there things people think are standard that are
used a lot?  



--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Learning how to use OpenSCAD

boxcarmib
I can only offer my own experience with OpenSCAD which I’ve been using for about 4 years, and to say that my knowledge and facility with OpenSCAD is driven primarily by the challenge of the final design. The open question... “How would I do that in OpenSCAD” and then setting about to make it happen.
If you’re lazy like me, you never really want to abandon the simple solutions and code flows you’ve mastered if they’ll do, but I’ve found it’s always useful to have the “Cheat Sheet” open in front of me, so that I’m always aware of options in functionality that I may not have tried yet.
My mastery of geometry is pathetic, so when I first examined mulmatrix() I gave it a wide berth, but if you want to sheer an object then there’s really no replacement (I say that somewhat embarrassed because in the early days I spent far too much time rotating cubes and slicing off sides :)) so even though I was loathe to climb the learning curve on that module, I eventually succeeded.
Then on the other hand, my personal experience is that life is just too short to make much use of minkowski() cause even though it's cool it can just take too staggeringly long to render some things so that I opt for a less sophisticated design rather than invoke the monster.
I have tried using the odd library, but once I figure out how a routine works I usually just rewrite it. The extensible nature of OpenSCAD where you can even replace all the existing modules with redefinition has left me with a rather extensive collection of routines in libraries of my own authorship, which means that my code doesn’t usually play well with others.
There’s also getting enough familiarity with OpenSCAD to develop an instinctive feel for what it can’t do… and others have experienced that too, so that every year or so you’ll see someone from the community innocently asking, “Can’t this feature be added to OpenSCAD” only to find that same feature was asked for a couple of years earlier and abandoned because it just can’t be accomplished with the way OpenSCAD interacts with it’s code base of other 3rd part modules. (For exampleI think we’d all love to have a way to extract the current point set at any point in our program… but as I understand it just isn’t possible. And wouldn’t it be neat to have some deformation routines, like “push this sphere into this cube”.
I know that I’d love to use some bezier curves in my designs, but from the little bit of investigation I’ve done in that area, looking at other people’s code and examples, it looks like the housekeeping requirements for keeping values alive and useful through transformations is beyond my ability to juggle more than on thing at a time.
I guess I would suggest that you set about writing routines that use every single function and module so that you develop a working knowledge of what they can do, and then their use will occur to you naturally when you cast about for how to solve your newest design challenge.
In short, I would say there’s just no substitute for doing lots of coding… always bearing in mind that regardless of what you’ve done, there’s probably a better smarter way of doing it that you may stumble across later.
Anyway, its always great to see someone else finding value in the OpenSCAD platform, for me, it is the parameterization that makes it the sole choice among modelling programs.
I’m sure others will have useful and helpful suggestions as well, as I can at least testify that the OpenSCAD community and its developers are by far the most welcoming, non-critical, helpful and patient bunch of folks probably on the whole planet.


> On Feb 19, 2019, at 4:14 PM, adrianv <[hidden email]> wrote:
>
> I've been using OpenSCAD for a while and lately as I've run across some more
> sophisticated code examples, I really started to wonder: how does one learn
> to use this tool?  The reference manual doesn't really give enough examples
> and explanations of how to use OpenSCAD.  Are there any really complete
> tutorials that explain everything?  
>
> It seems like a complete explanation would also include a description of
> libraries that are available, what exactly they can (and cannot) do, and how
> to use them.  I found a list of libraries, but it's difficult to determine
> what libraries actually can do.  And it's unclear how stable or "accepted"
> various libraries are.  Are there things people think are standard that are
> used a lot?  
>
>
>
> --
> Sent from: http://forum.openscad.org/
>
> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Learning how to use OpenSCAD

adrianv
Of course one can say you learn what you need to in order to make the design
you're trying to make.  But it wasn't apparent to me, for example, the way
that modules could use children and what (some of) the implications are.  I
still don't understand if it's possible to make a module that acts like
for_intersect().  It seems like the answer is no, but maybe I just didn't
figure it out.  And do I really understand all of what is possible with
modules?  I feel like the answer is no.  I agree that there's no substitute
for experience (e.g. lots of coding) but I also think there's no substitute
for outside guidance to learn tricks and techniques.  If "there's probably a
better smarter way of doing it" how am I ever going to find that?  

I'm using OpenSCAD to design for 3d printing and to me, the massive
challenge presenting for every design is how to ease all the edges.  Ideally
there should be no sharp right angle edges.  Minkowski is the only way to do
that, I think.  I've been using it a lot.  But in addition to taking a long
time, it changes the size of the model.  I built a model with "zero"
thickness so that I could then use minkowski, but this makes the design
tricky.  In a recent effort my design wasn't adhering to the build plate.  I
was baffled.  Then I realized that part of the model had been expanded by
minkowski using a sphere with radius 2, but the actual radius of the
(approximate) sphere was only 1.8, and hence part of my model was 0.2 mm
above the rest.  (This gotcha isn't limited to minkowski---if you try to
make a rounded cube using hull() and 8 spheres you'll also have issues.  I
suppose one answer is to push $fn high enough so that the error is always
much less than a print layer, but this hack doesn't seem like the elegant
fix.)  

In my most recent design I basically gave up on doing a proper round over
job, but I still wanted to cut off some corners in a few places, which
seemed to involve either a bunch of trial and error or a lot of calculations
to figure out where things end up in the model.  Some of these calculations
may be impossible in OpenSCAD (e.g. solutions to transcendental equations
that require an iterative solution)  It seems to me that if I construct an
object by intersecting two cubes I shouldn't have to then solve the
equations of the planes to find the line of intersection so I can operate on
that line (to add a roundover) because the program somehow knows where that
line is.   And in the case of adding the roundover there's the ongoing
question then about how to orient it correctly.   I think I spend about 10%
of my time coming up with the basic design and 90% trying to work out things
like this.  

Consider mulmatrix.  It's not apparent to me why this is useful, unless I
want to do something fairly complex involving iterated transformations.  It
sounds like I'm missing something.  I understand what matrix transformations
do and whatever I'm missing isn't obvious to me.   And the search()
function?  I have no clue what that could possibly be good for.  

It kind of sounds like you're saying we should all re-invent the wheel (our
own personal wheel?) which is not how I've gone about learning other
languages.  In C++ we have standard template libraries.  In Python we have
things like NumPy and SciPy.  You don't write your own personal libraries to
replace these standard ones.   The one argument against this would be that
OpenSCAD isn't really extensible and there's no benefit to be had from
libraries.  If, on the other hand, it's difficult or impossible to write
libraries so that they can coexist then that raises a question about the
basic design of OpenSCAD itself.

I hear that SOLIDWORKS also uses parameterization, so OpenSCAD isn't the
only game in town.  (But I think SOLIDWORKS is expensive.)  



--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Learning how to use OpenSCAD

nophead
The way to get rounded corners with the correct dimensions is to make sure $fn is a multiple of 4. That way the circle or sphere has vertices that align with the axes.

For 2D use offset for rounding and then linear_extrude for 2.5D. For full 3D use hull of spheres if possible and Minkowski with a sphere as last resort.

I rarely use multmatix. So far I have only used it to skew things as most other matrix operations can be done with translate, rotate, mirror and scale.

Yes OpenSCAD is far from unique in being parametric. Its main differences is you write script instead of interacting with a GUI. You only describe geometry with it, you can't interrogate it, You do need high school lever trigonometry to solve some problems with it. 


On Wed, 20 Feb 2019 at 13:04, adrianv <[hidden email]> wrote:
Of course one can say you learn what you need to in order to make the design
you're trying to make.  But it wasn't apparent to me, for example, the way
that modules could use children and what (some of) the implications are.  I
still don't understand if it's possible to make a module that acts like
for_intersect().  It seems like the answer is no, but maybe I just didn't
figure it out.  And do I really understand all of what is possible with
modules?  I feel like the answer is no.  I agree that there's no substitute
for experience (e.g. lots of coding) but I also think there's no substitute
for outside guidance to learn tricks and techniques.  If "there's probably a
better smarter way of doing it" how am I ever going to find that? 

I'm using OpenSCAD to design for 3d printing and to me, the massive
challenge presenting for every design is how to ease all the edges.  Ideally
there should be no sharp right angle edges.  Minkowski is the only way to do
that, I think.  I've been using it a lot.  But in addition to taking a long
time, it changes the size of the model.  I built a model with "zero"
thickness so that I could then use minkowski, but this makes the design
tricky.  In a recent effort my design wasn't adhering to the build plate.  I
was baffled.  Then I realized that part of the model had been expanded by
minkowski using a sphere with radius 2, but the actual radius of the
(approximate) sphere was only 1.8, and hence part of my model was 0.2 mm
above the rest.  (This gotcha isn't limited to minkowski---if you try to
make a rounded cube using hull() and 8 spheres you'll also have issues.  I
suppose one answer is to push $fn high enough so that the error is always
much less than a print layer, but this hack doesn't seem like the elegant
fix.) 

In my most recent design I basically gave up on doing a proper round over
job, but I still wanted to cut off some corners in a few places, which
seemed to involve either a bunch of trial and error or a lot of calculations
to figure out where things end up in the model.  Some of these calculations
may be impossible in OpenSCAD (e.g. solutions to transcendental equations
that require an iterative solution)  It seems to me that if I construct an
object by intersecting two cubes I shouldn't have to then solve the
equations of the planes to find the line of intersection so I can operate on
that line (to add a roundover) because the program somehow knows where that
line is.   And in the case of adding the roundover there's the ongoing
question then about how to orient it correctly.   I think I spend about 10%
of my time coming up with the basic design and 90% trying to work out things
like this. 

Consider mulmatrix.  It's not apparent to me why this is useful, unless I
want to do something fairly complex involving iterated transformations.  It
sounds like I'm missing something.  I understand what matrix transformations
do and whatever I'm missing isn't obvious to me.   And the search()
function?  I have no clue what that could possibly be good for. 

It kind of sounds like you're saying we should all re-invent the wheel (our
own personal wheel?) which is not how I've gone about learning other
languages.  In C++ we have standard template libraries.  In Python we have
things like NumPy and SciPy.  You don't write your own personal libraries to
replace these standard ones.   The one argument against this would be that
OpenSCAD isn't really extensible and there's no benefit to be had from
libraries.  If, on the other hand, it's difficult or impossible to write
libraries so that they can coexist then that raises a question about the
basic design of OpenSCAD itself.

I hear that SOLIDWORKS also uses parameterization, so OpenSCAD isn't the
only game in town.  (But I think SOLIDWORKS is expensive.) 



--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Learning how to use OpenSCAD

boxcarmib
I hope my original response to the OP didn’t come off as patronizing or simplistic, that wasn’t the intent… I clearly mis estimated the OP’s level of familiarity with OpenSCAD already.
I wasn’t suggesting that OpenSCAD was the only parametric design program out there but as you say, Solidworks IS expensive. At $4K a license I simply presumed that it was a non-starter for most people.
And I wasn’t trying to suggest that it one should rewrite all code, simply reporting on my own experience that often 3rd party libraries often point to the solution I need, but there always seems to be some other parameter or functionality I need to add for my own needs. Take for example Greg Frost’s Bevel and Spur gear library…. which is just a great contribution to the community but after having used it for awhile I discovered that I wanted gear designs that it could not accommodate. Personally I think 3rd party libraries are great in that they introduce (to me) new coding concepts and workable solutions, but that most of them are best thought of as tutorials that one can use very effectively to craft the solution for what is needed.
Because of the relatively modest popularity of OpenSCAD in the wider world, I find that it’s this mailing list that is the best source for outside guidance and learning tricks and techniques… and that was what my comment about the OpenSCAD community was really talking about… I’ve seen countless requests for help with design and coding that almost always result in helpful hints and discussions about the design at hand. Case in point… nop head’s response to your post and advice on setting $fn to multiples of 4.
For my part, I design models for 3D printing and try to craft code that will allow the things I create to be printed on any 3D printer, not just the ones I have access to. With that in mind, I came to appreciate that I needed to structure my code so that things like tolerance were parameterized at a very low level so that when Tab A needs to fit in Slot B, the desired fit can be achieved simply by changing a tolerance variable that works for a given machine… as out in the wild actual precision and accuracy varies a great deal.
And then there’s considerations like way OpenSCAD draws arcs and circles… and the need to mindful of final dimensions depending on whether you need an exterior cylinder or an interior knockout as discussed on this page… https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/undersized_circular_objects
You can implement a number of coding strategies to provide for the correct case, you could explicitly add the fudge factor whenever you need to draw an outer cylinder, or you can write unique methods for each use, or you can go for the approach I went for which was to provide a new cylinder method where the usage case is one of the parameters… e.g.

module _cylinder(height, radius, fn, usage = “default) {
r = usage == “default”
             ? radius
     : usage == “outer”
  ? radius * 1 / cos(180/fn)
  : radius * (1 + 1/cos(180/fn))/2;
cylinder(height,r,fn);

As a result of this kind of approach, and to accommodate the previously mentioned concerns about tolerance, I no longer call cylinder() in my code, but my own _cylinder() which notches up the level of abstraction of the objects I’m creating and helps me personally write what I find to be code that’s easier to understand.
Again I apologize if my original post implied anything more than was intended which was to offer encouragement and identify that for me, this forum is the best one-stop spot for everything OpenSCAD.




On Feb 20, 2019, at 7:48 AM, nop head <[hidden email]> wrote:

The way to get rounded corners with the correct dimensions is to make sure $fn is a multiple of 4. That way the circle or sphere has vertices that align with the axes.

For 2D use offset for rounding and then linear_extrude for 2.5D. For full 3D use hull of spheres if possible and Minkowski with a sphere as last resort.

I rarely use multmatix. So far I have only used it to skew things as most other matrix operations can be done with translate, rotate, mirror and scale.

Yes OpenSCAD is far from unique in being parametric. Its main differences is you write script instead of interacting with a GUI. You only describe geometry with it, you can't interrogate it, You do need high school lever trigonometry to solve some problems with it. 


On Wed, 20 Feb 2019 at 13:04, adrianv <[hidden email]> wrote:
Of course one can say you learn what you need to in order to make the design
you're trying to make.  But it wasn't apparent to me, for example, the way
that modules could use children and what (some of) the implications are.  I
still don't understand if it's possible to make a module that acts like
for_intersect().  It seems like the answer is no, but maybe I just didn't
figure it out.  And do I really understand all of what is possible with
modules?  I feel like the answer is no.  I agree that there's no substitute
for experience (e.g. lots of coding) but I also think there's no substitute
for outside guidance to learn tricks and techniques.  If "there's probably a
better smarter way of doing it" how am I ever going to find that? 

I'm using OpenSCAD to design for 3d printing and to me, the massive
challenge presenting for every design is how to ease all the edges.  Ideally
there should be no sharp right angle edges.  Minkowski is the only way to do
that, I think.  I've been using it a lot.  But in addition to taking a long
time, it changes the size of the model.  I built a model with "zero"
thickness so that I could then use minkowski, but this makes the design
tricky.  In a recent effort my design wasn't adhering to the build plate.  I
was baffled.  Then I realized that part of the model had been expanded by
minkowski using a sphere with radius 2, but the actual radius of the
(approximate) sphere was only 1.8, and hence part of my model was 0.2 mm
above the rest.  (This gotcha isn't limited to minkowski---if you try to
make a rounded cube using hull() and 8 spheres you'll also have issues.  I
suppose one answer is to push $fn high enough so that the error is always
much less than a print layer, but this hack doesn't seem like the elegant
fix.) 

In my most recent design I basically gave up on doing a proper round over
job, but I still wanted to cut off some corners in a few places, which
seemed to involve either a bunch of trial and error or a lot of calculations
to figure out where things end up in the model.  Some of these calculations
may be impossible in OpenSCAD (e.g. solutions to transcendental equations
that require an iterative solution)  It seems to me that if I construct an
object by intersecting two cubes I shouldn't have to then solve the
equations of the planes to find the line of intersection so I can operate on
that line (to add a roundover) because the program somehow knows where that
line is.   And in the case of adding the roundover there's the ongoing
question then about how to orient it correctly.   I think I spend about 10%
of my time coming up with the basic design and 90% trying to work out things
like this. 

Consider mulmatrix.  It's not apparent to me why this is useful, unless I
want to do something fairly complex involving iterated transformations.  It
sounds like I'm missing something.  I understand what matrix transformations
do and whatever I'm missing isn't obvious to me.   And the search()
function?  I have no clue what that could possibly be good for. 

It kind of sounds like you're saying we should all re-invent the wheel (our
own personal wheel?) which is not how I've gone about learning other
languages.  In C++ we have standard template libraries.  In Python we have
things like NumPy and SciPy.  You don't write your own personal libraries to
replace these standard ones.   The one argument against this would be that
OpenSCAD isn't really extensible and there's no benefit to be had from
libraries.  If, on the other hand, it's difficult or impossible to write
libraries so that they can coexist then that raises a question about the
basic design of OpenSCAD itself.

I hear that SOLIDWORKS also uses parameterization, so OpenSCAD isn't the
only game in town.  (But I think SOLIDWORKS is expensive.) 



--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Learning how to use OpenSCAD

JordanBrown
In reply to this post by boxcarmib
On 2/19/2019 6:12 PM, Hugo Jackson wrote:
I know that I’d love to use some bezier curves in my designs, but from the little bit of investigation I’ve done in that area, looking at other people’s code and examples, it looks like the housekeeping requirements for keeping values alive and useful through transformations is beyond my ability to juggle more than on thing at a time.

At least for 2D beziers, the math is a little scary but once you've got a function that emits a series of points it's not bad. You just feed that list into polygon() and can then extrude and transform to your heart's desire.  Note that you will often want to concatenate bezier curves and straight lines to form your polygon.

I'm sure that 3D bezier curves are meaningful, but they hurt my head.

// Bezier functions from https://www.thingiverse.com/thing:8443
// but that yielded either single points or a raft of triangles;
// this yields a vector of points that you can then concatenate
// with other pieces to form a single polygon.
// If we were really clever, I think it would be possible to
// automatically space the output points based on how linear
// the curve is at that point.  But right now I'm not that clever.
function BEZ03(u) = pow((1-u), 3);
function BEZ13(u) = 3*u*(pow((1-u),2));
function BEZ23(u) = 3*(pow(u,2))*(1-u);
function BEZ33(u) = pow(u,3);

function PointAlongBez4(p0, p1, p2, p3, u) = [
	BEZ03(u)*p0[0]+BEZ13(u)*p1[0]+BEZ23(u)*p2[0]+BEZ33(u)*p3[0],
	BEZ03(u)*p0[1]+BEZ13(u)*p1[1]+BEZ23(u)*p2[1]+BEZ33(u)*p3[1]];

// p0 - start point
// p1 - control point 1, line departs p0 headed this way
// p2 - control point 2, line arrives at p3 from this way
// p3 - end point
// segs - number of segments
function bez(p0, p1, p2, p3, segs) = [
    for (i = [0:segs]) PointAlongBez4(p0, p1, p2, p3, i/segs)
];


// And an example...

b = bez([0,10], [5,15], [5,5], [10,10], 10);
linear_extrude(height=5) polygon(concat([[10,0], [0,0]], b));


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Learning how to use OpenSCAD

JordanBrown
In reply to this post by adrianv
On 2/20/2019 4:59 AM, adrianv wrote:
Of course one can say you learn what you need to in order to make the design
you're trying to make.  But it wasn't apparent to me, for example, the way
that modules could use children and what (some of) the implications are.


Have you read this tutorial?

http://www.tridimake.com/2014/09/how-to-use-openscad-tricks-and-tips-to.html

It covers children in section 4.

The capsule summary is that you can write a module that can consume child objects and manipulate them.

module double(offset) {
    children();
    translate(offset) children();
}

double([3,0,0]) cube(1);


    
Consider mulmatrix.  It's not apparent to me why this is useful,


Skewing.  This example skews in x and y based on z - that is, as z gets bigger, x and y translate.

module skewz(x, y) {
    multmatrix([
        [ 1, 0, x, 0 ],
        [ 0, 1, y, 0 ],
        [ 0, 0, 1, 0 ],
        [ 0, 0, 0, 1 ]
    ]) children();
}

skewz(1,1) cube(1);

And the search() function?  I have no clue what that could possibly be good for.

Lookup tables.  I've only used it once (and that only as a proof of concept for somebody else).

I don't remember what the original question was, but here's a function that draws text one character at a time, using a character-width table.  The key part is the cw() function.

// Table of character widths.
// These values approximate the default font for text() on Windows.
// Punctuation and digits left as an exercise for the reader.
widths = [
    ["A", 9],
    ["B", 9],
    ["C", 9],
    ["D", 10],
    ["E", 9],
    ["F", 9],
    ["G", 10],
    ["H", 10],
    ["I", 4],
    ["J", 7],
    ["K", 9],
    ["L", 8],
    ["M", 11],
    ["N", 9],
    ["O", 10],
    ["P", 9],
    ["Q", 10],
    ["R", 10],
    ["S", 9],
    ["T", 9],
    ["U", 9],
    ["V", 9],
    ["W", 13],
    ["X", 9],
    ["Y", 9],
    ["Z", 9],
    ["a", 7.5],
    ["b", 7.5],
    ["c", 7.5],
    ["d", 7.5],
    ["e", 7.5],
    ["f", 4],
    ["g", 7.5],
    ["h", 7.5],
    ["i", 3],
    ["j", 3],
    ["k", 7.5],
    ["l", 3],
    ["m", 11],
    ["n", 7.5],
    ["o", 7.5],
    ["p", 7.5],
    ["q", 7.5],
    ["r", 4.5],
    ["s", 7.5],
    ["t", 4],
    ["u", 7.5],
    ["v", 7],
    ["w", 9],
    ["x", 7],
    ["y", 6.5],
    ["z", 7.5],
];

// Given a character c (as a single-character string), return its width
function cw(c) = widths[search(c, widths, index_col_num=0)[0][0]][1];

// Given a string s and a length n, return the total width of the first n characters of s.  n defaults to the length of s.
function sw(s, n) = let(_n = n != undef ? n : len(s)) _n == 0 ? 0 : sw(s, _n-1) + cw(s[_n-1]);

// Draw a string s using the text defaults.
// This variation calculates the position of each character individually.
// Note that a real implementation would need to allow setting the size of the text, and would need to scale the widths based on the text size.
module text2(s) {
    for (i = [0:len(s)-1]) {
        translate([sw(s, i),0,0]) text(s[i]);
    }
}

// Draw a string using the text defaults.
// This variation positions each character relative to the character before it.
// Again, a real implementation would need to allow for changing the font size.
module text3(s, start) {
    _start = start != undef ? start : 0;
    if (_start <= len(s)) {
        text(s[_start]);
        if (_start+1 <= len(s)) {
            translate([cw(s[_start]),0,0]) text3(s, _start+1);
        }
    }
}

// Test case comparing the spacing generated here with the default spacing.
s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
text(s);
translate([0,12,0]) text2(s);
translate([0,24,0]) text3(s);

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Learning how to use OpenSCAD

adrianv
In reply to this post by nophead
nophead wrote
> The way to get rounded corners with the correct dimensions is to make sure
> $fn is a multiple of 4. That way the circle or sphere has vertices that
> align with the axes.

This is not sufficient.  In my original case I had $fn=8 and that resulted
in my model being unprintable due to the discrepancy.  In 2d forcing $fn=4
works.  But in 3d, you have to force $fn=4 and you also have to correct the
radius by the cos(180/$fn) factor.  At least, I think that works.  I don't
have a mechanism for making sure that my code is actually correct.   (Maybe
I should try to read the STL files.)  

module boundcube(x,y,z,r=0,facets=20)
{
  if (r==0)
    translate([x[0],y[0],z[0]])
      cube(size=[x[1]-x[0],y[1]-y[0],z[1]-z[0]],center=false);
  else {
    fixfacets = ceil(facets/4)*4;   // Force facets to a multiple of 4    
    fixr = r/cos(180/facets);
    hull()
      for(i=[0,1])
        for(j=[0,1])
          for(k=[0,1])
            translate([x[i]-2*i*r+r, y[j]-2*j*r+r, z[k]-2*k*r+r])
              sphere(r=fixr, $fn=fixfacets);
  }
}

If you know what you're doing ahead of time, so to speak, then I think it's
easier to build roundovers into the design.  In the cases I'm thinking of I
constructed a model using a series of operations and then wanted the result
to have a roundover.  In once case, the model was fairly simple, resulting
from the intersection of cubes.  So I could have worked out the equations of
the cube faces to figure out their intersections and hence determined the
line of intersection and then placed my roundover there.  But in the second
case, I started with a shape made from a cos wave joined up to a tangent
function, which I expanded using offset() and then extruded into 3d, and
then I used minkowski to turn it into a hollow shape with thin walls.  Now I
want to cut off and round over some of those walls.  Figuring out exactly
where those walls are so I can round them over doesn't appear to be straight
forward, and I created a roundover shape and then shifted it around by trial
and error, which makes the model less parametric than one might like.  I
considered the goal of rounding over the entire edge of the shape, which
follows a cos wave---except not quite because of the offset.  I have no idea
how that could be accomplished short of redoing the model in a fully
functional (mathematical) fashion using polyhedron(), or trying to apply
minkowski again on it.   It was slow enough with one minkowski.   A more
general issue with minkowski is the need to design the model undersized to
make it work.  In one recent design I was making a box with cylinderical
holes and wanted the edge of the box and also the edges of the holes to have
a roundover.  I did this by subtracting cylinders from the cube, running
minkowski, and then subtracting the cylinders again to remove the excess.
This seems sort of messy.  But trying to construct roundover cylinders
seemed messier.   And of course it happens that you want to round over just
parts of the model, which minowski cannot do.

In response to Hugo Jackson, wouldn't it be better to extend the Gear
library to remove its limitations in a new library version rather than to
rewrite it yourself, for your own private version?   I suppose there's
always the risk of things getting overwhelmingly complex due to special case
situations.   But if the OpenSCAD community regards libraries as method
tutorials rather than as building blocks it seems like we're never going to
build very high.  And if its the nature of OpenSCAD that you can't build on
top of libraries but always need to rewrite them, that seems disturbing.  It
suggests that the environment is fundamentally limited, that it has a design
flaw of some kind.  Or maybe the library design isn't good.  But then we
need to know how to write a good, extensible library.  

It would seem perfectly reasonable for OpenSCAD to provide primitive
operations like cylinder() but for there to be a set of standard libraries
that provide things like adjustment for the polygonal nature of cylinders.  
But why should everybody have to (1) figure out the need for this and then
(2) write it himself?  

Every time I do a design I feel like I'm stumbling around trying to find
clean or elegant solutions to problem in the design.  It doesn't really seem
like I should be trying to crowdsource my modeling by posting all of these
problems here.  That's also inefficient for the community in general.   I
normally figure that when encountering a programming difficulty one should
reduce it to the essential minimal example, but that seems harder to do than
in other programming contexts.  Or the minimal examples are bigger.   Maybe
I just need to work harder at the reduction.  




--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Learning how to use OpenSCAD

adrianv
In reply to this post by JordanBrown
JordanBrown wrote

> On 2/20/2019 4:59 AM, adrianv wrote:
>> Of course one can say you learn what you need to in order to make the
>> design
>> you're trying to make.  But it wasn't apparent to me, for example, the
>> way
>> that modules could use children and what (some of) the implications are.
>
>
> Have you read this tutorial?
>
> http://www.tridimake.com/2014/09/how-to-use-openscad-tricks-and-tips-to.html
>
> It covers children in section 4.

Yes.  That tutorial was what opened my eyes to this whole capability.  But I
had to stumble across it.  It also raises the question about applying my own
module to a loop when they describe how their chained_hull() module won't
work on the output of for(), since for() just produces one child.   That's
what caused me to ask the question about whether I can write my own for()
function.  Certainly the code example where he hard codes the wedge_if calls
in a big list seems pretty darn ugly.  Is that the best that is possible?
It seems like being able to write my own iteration, or to operate on the
separate children of a for loop, would be a useful feature.  I assume
there's some reason it missing.  It is impossible, right?  

Note: I recognize what can be done with matrix transformations.  I'm just
not seeing (at the moment) an application for it.  And if it's only good for
making skews, really, then it seems like you really just want to write the
skew() module and never look at mulmatrix again, due to its increased
complexity.   I mean, one could argue we don't need rotate() or translate()
since mulmatrix() can do it all.  One could imagine OpenSCAD implemented
with only mulmatrix() in the core language and with those other functions as
a library layer over it.  

I saw in another message somebody searching vertex lists with search() for
some purpose that I didn't fully understand.  Lookup tables on single
characters seems like a pretty contrived example.  




--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Learning how to use OpenSCAD

boxcarmib
In reply to this post by adrianv
I think the greatest handicap OpenSCAD faces is the vicious circle of popularity vs. participation. I believe I read somewhere that you can count on one hand the number of people who’ve taken on the task of OpenSCAD development and maintenance… and as a consequence there are far more features and functionality that end users would like to see than there are people who have the time and resources to implement the wish lists.
As for my obligation to update the gear library, you make a good point. In my defence while I occasionally see requests for “where to find a gear library”, once they’re pointed to the existing contribution then that’s usually the end of it, so my assumption is that the existing library is giving people the functionality they need and no necessity to muddy the water with my own contribution. But perhaps it's simply that the existing library failed to meet their needs and they moved on in frustration.
But you’re right, it would be good to have more community endorsed libraries, and if I were to make a suggestion to the OpenSCAD maintainers it would be have an explicit and separate area on GitHub for OpenSCAD libraries. As it stands, its seems that the primary repository for OpenSCAD libraries is Thingiverse. While I don’t feel up to the challenge of modifying OpenSCAD itself, I’d be on board with supplying and participating in the development of library routines written in OpenSCAD.

> On Feb 20, 2019, at 10:55 AM, adrianv <[hidden email]> wrote:
>
> nophead wrote
>> The way to get rounded corners with the correct dimensions is to make sure
>> $fn is a multiple of 4. That way the circle or sphere has vertices that
>> align with the axes.
>
> This is not sufficient.  In my original case I had $fn=8 and that resulted
> in my model being unprintable due to the discrepancy.  In 2d forcing $fn=4
> works.  But in 3d, you have to force $fn=4 and you also have to correct the
> radius by the cos(180/$fn) factor.  At least, I think that works.  I don't
> have a mechanism for making sure that my code is actually correct.   (Maybe
> I should try to read the STL files.)  
>
> module boundcube(x,y,z,r=0,facets=20)
> {
>  if (r==0)
>    translate([x[0],y[0],z[0]])
>      cube(size=[x[1]-x[0],y[1]-y[0],z[1]-z[0]],center=false);
>  else {
>    fixfacets = ceil(facets/4)*4;   // Force facets to a multiple of 4    
>    fixr = r/cos(180/facets);
>    hull()
>      for(i=[0,1])
>        for(j=[0,1])
>          for(k=[0,1])
>            translate([x[i]-2*i*r+r, y[j]-2*j*r+r, z[k]-2*k*r+r])
>              sphere(r=fixr, $fn=fixfacets);
>  }
> }
>
> If you know what you're doing ahead of time, so to speak, then I think it's
> easier to build roundovers into the design.  In the cases I'm thinking of I
> constructed a model using a series of operations and then wanted the result
> to have a roundover.  In once case, the model was fairly simple, resulting
> from the intersection of cubes.  So I could have worked out the equations of
> the cube faces to figure out their intersections and hence determined the
> line of intersection and then placed my roundover there.  But in the second
> case, I started with a shape made from a cos wave joined up to a tangent
> function, which I expanded using offset() and then extruded into 3d, and
> then I used minkowski to turn it into a hollow shape with thin walls.  Now I
> want to cut off and round over some of those walls.  Figuring out exactly
> where those walls are so I can round them over doesn't appear to be straight
> forward, and I created a roundover shape and then shifted it around by trial
> and error, which makes the model less parametric than one might like.  I
> considered the goal of rounding over the entire edge of the shape, which
> follows a cos wave---except not quite because of the offset.  I have no idea
> how that could be accomplished short of redoing the model in a fully
> functional (mathematical) fashion using polyhedron(), or trying to apply
> minkowski again on it.   It was slow enough with one minkowski.   A more
> general issue with minkowski is the need to design the model undersized to
> make it work.  In one recent design I was making a box with cylinderical
> holes and wanted the edge of the box and also the edges of the holes to have
> a roundover.  I did this by subtracting cylinders from the cube, running
> minkowski, and then subtracting the cylinders again to remove the excess.
> This seems sort of messy.  But trying to construct roundover cylinders
> seemed messier.   And of course it happens that you want to round over just
> parts of the model, which minowski cannot do.
>
> In response to Hugo Jackson, wouldn't it be better to extend the Gear
> library to remove its limitations in a new library version rather than to
> rewrite it yourself, for your own private version?   I suppose there's
> always the risk of things getting overwhelmingly complex due to special case
> situations.   But if the OpenSCAD community regards libraries as method
> tutorials rather than as building blocks it seems like we're never going to
> build very high.  And if its the nature of OpenSCAD that you can't build on
> top of libraries but always need to rewrite them, that seems disturbing.  It
> suggests that the environment is fundamentally limited, that it has a design
> flaw of some kind.  Or maybe the library design isn't good.  But then we
> need to know how to write a good, extensible library.  
>
> It would seem perfectly reasonable for OpenSCAD to provide primitive
> operations like cylinder() but for there to be a set of standard libraries
> that provide things like adjustment for the polygonal nature of cylinders.  
> But why should everybody have to (1) figure out the need for this and then
> (2) write it himself?  
>
> Every time I do a design I feel like I'm stumbling around trying to find
> clean or elegant solutions to problem in the design.  It doesn't really seem
> like I should be trying to crowdsource my modeling by posting all of these
> problems here.  That's also inefficient for the community in general.   I
> normally figure that when encountering a programming difficulty one should
> reduce it to the essential minimal example, but that seems harder to do than
> in other programming contexts.  Or the minimal examples are bigger.   Maybe
> I just need to work harder at the reduction.  
>
>
>
>
> --
> Sent from: http://forum.openscad.org/
>
> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Learning how to use OpenSCAD

nophead
This is not sufficient.  In my original case I had $fn=8 and that resulted in my model being unprintable due to the discrepancy.
 
Oh yes, spheres are a bit broken. Here you can see that a circle of radius 10 has its vertices exactly on 10.

image.png

But sphere doesn't get the poles and the equator correct as it starts the latitude circles half an angle out.  So yes dividing the cos(180 / $fn) fixes it.

image.png

Alternatively, writing ones own with polyhedron is probably better. 

I always learn from this forum.

I assume there's some reason it missing.  It is impossible, right?    

All modules currently can only return one child even though they can have more than one child themselves. It is an implementation limitation and may change. There is even a pull request for a version of for with union = false as an option. https://github.com/openscad/openscad/pull/2796


On Wed, 20 Feb 2019 at 19:38, Hugo Jackson <[hidden email]> wrote:
I think the greatest handicap OpenSCAD faces is the vicious circle of popularity vs. participation. I believe I read somewhere that you can count on one hand the number of people who’ve taken on the task of OpenSCAD development and maintenance… and as a consequence there are far more features and functionality that end users would like to see than there are people who have the time and resources to implement the wish lists.
As for my obligation to update the gear library, you make a good point. In my defence while I occasionally see requests for “where to find a gear library”, once they’re pointed to the existing contribution then that’s usually the end of it, so my assumption is that the existing library is giving people the functionality they need and no necessity to muddy the water with my own contribution. But perhaps it's simply that the existing library failed to meet their needs and they moved on in frustration.
But you’re right, it would be good to have more community endorsed libraries, and if I were to make a suggestion to the OpenSCAD maintainers it would be have an explicit and separate area on GitHub for OpenSCAD libraries. As it stands, its seems that the primary repository for OpenSCAD libraries is Thingiverse. While I don’t feel up to the challenge of modifying OpenSCAD itself, I’d be on board with supplying and participating in the development of library routines written in OpenSCAD.

> On Feb 20, 2019, at 10:55 AM, adrianv <[hidden email]> wrote:
>
> nophead wrote
>> The way to get rounded corners with the correct dimensions is to make sure
>> $fn is a multiple of 4. That way the circle or sphere has vertices that
>> align with the axes.
>
> This is not sufficient.  In my original case I had $fn=8 and that resulted
> in my model being unprintable due to the discrepancy.  In 2d forcing $fn=4
> works.  But in 3d, you have to force $fn=4 and you also have to correct the
> radius by the cos(180/$fn) factor.  At least, I think that works.  I don't
> have a mechanism for making sure that my code is actually correct.   (Maybe
> I should try to read the STL files.) 
>
> module boundcube(x,y,z,r=0,facets=20)
> {
>  if (r==0)
>    translate([x[0],y[0],z[0]])
>      cube(size=[x[1]-x[0],y[1]-y[0],z[1]-z[0]],center=false);
>  else {
>    fixfacets = ceil(facets/4)*4;   // Force facets to a multiple of 4     
>    fixr = r/cos(180/facets);
>    hull()
>      for(i=[0,1])
>        for(j=[0,1])
>          for(k=[0,1])
>            translate([x[i]-2*i*r+r, y[j]-2*j*r+r, z[k]-2*k*r+r])
>              sphere(r=fixr, $fn=fixfacets);
>  }
> }
>
> If you know what you're doing ahead of time, so to speak, then I think it's
> easier to build roundovers into the design.  In the cases I'm thinking of I
> constructed a model using a series of operations and then wanted the result
> to have a roundover.  In once case, the model was fairly simple, resulting
> from the intersection of cubes.  So I could have worked out the equations of
> the cube faces to figure out their intersections and hence determined the
> line of intersection and then placed my roundover there.  But in the second
> case, I started with a shape made from a cos wave joined up to a tangent
> function, which I expanded using offset() and then extruded into 3d, and
> then I used minkowski to turn it into a hollow shape with thin walls.  Now I
> want to cut off and round over some of those walls.  Figuring out exactly
> where those walls are so I can round them over doesn't appear to be straight
> forward, and I created a roundover shape and then shifted it around by trial
> and error, which makes the model less parametric than one might like.  I
> considered the goal of rounding over the entire edge of the shape, which
> follows a cos wave---except not quite because of the offset.  I have no idea
> how that could be accomplished short of redoing the model in a fully
> functional (mathematical) fashion using polyhedron(), or trying to apply
> minkowski again on it.   It was slow enough with one minkowski.   A more
> general issue with minkowski is the need to design the model undersized to
> make it work.  In one recent design I was making a box with cylinderical
> holes and wanted the edge of the box and also the edges of the holes to have
> a roundover.  I did this by subtracting cylinders from the cube, running
> minkowski, and then subtracting the cylinders again to remove the excess.
> This seems sort of messy.  But trying to construct roundover cylinders
> seemed messier.   And of course it happens that you want to round over just
> parts of the model, which minowski cannot do.
>
> In response to Hugo Jackson, wouldn't it be better to extend the Gear
> library to remove its limitations in a new library version rather than to
> rewrite it yourself, for your own private version?   I suppose there's
> always the risk of things getting overwhelmingly complex due to special case
> situations.   But if the OpenSCAD community regards libraries as method
> tutorials rather than as building blocks it seems like we're never going to
> build very high.  And if its the nature of OpenSCAD that you can't build on
> top of libraries but always need to rewrite them, that seems disturbing.  It
> suggests that the environment is fundamentally limited, that it has a design
> flaw of some kind.  Or maybe the library design isn't good.  But then we
> need to know how to write a good, extensible library. 
>
> It would seem perfectly reasonable for OpenSCAD to provide primitive
> operations like cylinder() but for there to be a set of standard libraries
> that provide things like adjustment for the polygonal nature of cylinders. 
> But why should everybody have to (1) figure out the need for this and then
> (2) write it himself? 
>
> Every time I do a design I feel like I'm stumbling around trying to find
> clean or elegant solutions to problem in the design.  It doesn't really seem
> like I should be trying to crowdsource my modeling by posting all of these
> problems here.  That's also inefficient for the community in general.   I
> normally figure that when encountering a programming difficulty one should
> reduce it to the essential minimal example, but that seems harder to do than
> in other programming contexts.  Or the minimal examples are bigger.   Maybe
> I just need to work harder at the reduction. 
>
>
>
>
> --
> Sent from: http://forum.openscad.org/
>
> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Learning how to use OpenSCAD

lostapathy
In reply to this post by boxcarmib
OpenSCAD has a weird relationship with libraries.  I think there's fundamentally 2 problems that feed each other.

1)  No package manager has ever really gained much adoption. (I've tried - I'm the author of https://github.com/lostapathy/scad_bundler).  Which probably makes sense because there aren't many libraries packaged for any package manager.

2)  There's not a lot of community knowledge on how to make a library that is well suited for reuse (or extract one from a larger project).

There's definitely a bootstrapping problem here.  I personally think a lot of the perceived limitations of OpenSCAD can be solved at the library level, and having a more compelling ecosystem there will attract more effort in OpenSCAD itself.

I haven't spent much time on scad_bundler recently because I never got much interest or engagement on it - good bad or otherwise.  Perhaps there's a mismatch in that I'm trying to approach using OpenSCAD like a software engineering problem, and maybe that's not where the community is at.  At the same time, "post your library on thingiverse" hasn't really taken off, either.

I'm not sure what the next step is, but I'm open to suggestions. 






On 2/20/19 1:37 PM, Hugo Jackson wrote:
I think the greatest handicap OpenSCAD faces is the vicious circle of popularity vs. participation. I believe I read somewhere that you can count on one hand the number of people who’ve taken on the task of OpenSCAD development and maintenance… and as a consequence there are far more features and functionality that end users would like to see than there are people who have the time and resources to implement the wish lists.
As for my obligation to update the gear library, you make a good point. In my defence while I occasionally see requests for “where to find a gear library”, once they’re pointed to the existing contribution then that’s usually the end of it, so my assumption is that the existing library is giving people the functionality they need and no necessity to muddy the water with my own contribution. But perhaps it's simply that the existing library failed to meet their needs and they moved on in frustration.
But you’re right, it would be good to have more community endorsed libraries, and if I were to make a suggestion to the OpenSCAD maintainers it would be have an explicit and separate area on GitHub for OpenSCAD libraries. As it stands, its seems that the primary repository for OpenSCAD libraries is Thingiverse. While I don’t feel up to the challenge of modifying OpenSCAD itself, I’d be on board with supplying and participating in the development of library routines written in OpenSCAD.

On Feb 20, 2019, at 10:55 AM, adrianv [hidden email] wrote:

nophead wrote
The way to get rounded corners with the correct dimensions is to make sure
$fn is a multiple of 4. That way the circle or sphere has vertices that
align with the axes.
This is not sufficient.  In my original case I had $fn=8 and that resulted
in my model being unprintable due to the discrepancy.  In 2d forcing $fn=4
works.  But in 3d, you have to force $fn=4 and you also have to correct the
radius by the cos(180/$fn) factor.  At least, I think that works.  I don't
have a mechanism for making sure that my code is actually correct.   (Maybe
I should try to read the STL files.)  

module boundcube(x,y,z,r=0,facets=20)
{
 if (r==0)
   translate([x[0],y[0],z[0]])
     cube(size=[x[1]-x[0],y[1]-y[0],z[1]-z[0]],center=false);
 else {
   fixfacets = ceil(facets/4)*4;   // Force facets to a multiple of 4     
   fixr = r/cos(180/facets);
   hull()
     for(i=[0,1])
       for(j=[0,1])
         for(k=[0,1])
           translate([x[i]-2*i*r+r, y[j]-2*j*r+r, z[k]-2*k*r+r])
             sphere(r=fixr, $fn=fixfacets);
 }
}

If you know what you're doing ahead of time, so to speak, then I think it's
easier to build roundovers into the design.  In the cases I'm thinking of I
constructed a model using a series of operations and then wanted the result
to have a roundover.  In once case, the model was fairly simple, resulting
from the intersection of cubes.  So I could have worked out the equations of
the cube faces to figure out their intersections and hence determined the
line of intersection and then placed my roundover there.  But in the second
case, I started with a shape made from a cos wave joined up to a tangent
function, which I expanded using offset() and then extruded into 3d, and
then I used minkowski to turn it into a hollow shape with thin walls.  Now I
want to cut off and round over some of those walls.  Figuring out exactly
where those walls are so I can round them over doesn't appear to be straight
forward, and I created a roundover shape and then shifted it around by trial
and error, which makes the model less parametric than one might like.  I
considered the goal of rounding over the entire edge of the shape, which
follows a cos wave---except not quite because of the offset.  I have no idea
how that could be accomplished short of redoing the model in a fully
functional (mathematical) fashion using polyhedron(), or trying to apply
minkowski again on it.   It was slow enough with one minkowski.   A more
general issue with minkowski is the need to design the model undersized to
make it work.  In one recent design I was making a box with cylinderical
holes and wanted the edge of the box and also the edges of the holes to have
a roundover.  I did this by subtracting cylinders from the cube, running
minkowski, and then subtracting the cylinders again to remove the excess. 
This seems sort of messy.  But trying to construct roundover cylinders
seemed messier.   And of course it happens that you want to round over just
parts of the model, which minowski cannot do.

In response to Hugo Jackson, wouldn't it be better to extend the Gear
library to remove its limitations in a new library version rather than to
rewrite it yourself, for your own private version?   I suppose there's
always the risk of things getting overwhelmingly complex due to special case
situations.   But if the OpenSCAD community regards libraries as method
tutorials rather than as building blocks it seems like we're never going to
build very high.  And if its the nature of OpenSCAD that you can't build on
top of libraries but always need to rewrite them, that seems disturbing.  It
suggests that the environment is fundamentally limited, that it has a design
flaw of some kind.  Or maybe the library design isn't good.  But then we
need to know how to write a good, extensible library.  

It would seem perfectly reasonable for OpenSCAD to provide primitive
operations like cylinder() but for there to be a set of standard libraries
that provide things like adjustment for the polygonal nature of cylinders.  
But why should everybody have to (1) figure out the need for this and then
(2) write it himself?  

Every time I do a design I feel like I'm stumbling around trying to find
clean or elegant solutions to problem in the design.  It doesn't really seem
like I should be trying to crowdsource my modeling by posting all of these
problems here.  That's also inefficient for the community in general.   I
normally figure that when encountering a programming difficulty one should
reduce it to the essential minimal example, but that seems harder to do than
in other programming contexts.  Or the minimal examples are bigger.   Maybe
I just need to work harder at the reduction.  




--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org



_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Learning how to use OpenSCAD

adrianv
In reply to this post by nophead
nophead wrote

>>
>> This is not sufficient.  In my original case I had $fn=8 and that
>> resulted
>> in my model being unprintable due to the discrepancy.
>
>
> Oh yes, spheres are a bit broken. Here you can see that a circle of radius
> 10 has its vertices exactly on 10.
>
> [image: image.png]

Actually all I can tell from that picture is that the circle is close to 10.
I can't tell that it's exactly ten.  Could be 10.1 maybe.  Could it be 10.2?
Maybe.  

I went ahead and looked at the STL for
linear_extrude(height=1)circle(r=1,$fn=8); and found that it looks like
this:

solid OpenSCAD_Model
  facet normal 0 0 -1
    outer loop
      vertex 0.707107 0.707107 0
      vertex 1 0 0
      vertex 0.707107 -0.707107 0
    endloop
  endfacet
  facet normal -0 -0 -1
    outer loop
      vertex 0.707107 0.707107 0
      vertex 0.707107 -0.707107 0
      vertex -0.707107 0.707107 0
    endloop
  endfacet
  facet normal 0 0 -1
    outer loop
      vertex 0.707107 0.707107 0
      vertex -0.707107 0.707107 0
      vertex 6.12323e-17 1 0
    endloop
  endfacet
  facet normal 0 -0 -1
    outer loop
      vertex -0.707107 0.707107 0
      vertex -1.83697e-16 -1 0
      vertex -1 1.22465e-16 0
    endloop
  endfacet

etc, etc, etc

I loaded the data into octave and checked that the x and y range from -1 to
1 and that furthermore, all values above 0.9 are equal to 1 and all values
below -0.9 are less than 1.  So that's confirmation that nothing surprising
has happened.  I suppose I ought to do the same thing for my boundcube()
module.  





--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Learning how to use OpenSCAD

MichaelAtOz
Administrator
In reply to this post by lostapathy
lostapathy wrote
> OpenSCAD has a weird relationship with libraries. 
> 1)  No package manager has ever really gained much adoption
>
> 2)  There's not a lot of community knowledge on how to make a library

3)  The language needs additional features to better support libraries. e.g.
Namespaces

There has been much discussion on the future direction of OpenSCAD including
many such features, see  here
<https://github.com/openscad/openscad/wiki/OpenSCAD-Enhancement-Proposals>  
&  here <https://github.com/doug-moen/openscad2/blob/master/README.md>   for
example, plus much past discussion in the headspace of the development
community. Note that they are proposals and still need design work (IMHO)
and not necessarily fully endorsed direction.

But as Hugo mentions, there is only a small pool of spare-time developers,
the resources available vary, so progress has to go in baby steps. An
unfortunate reality.

It should also be noted that OpenSCAD is young, according to Wikipedia, the
initial release was 19 February 2010. Happy 9th Birthday!! And only really 4
major releases in that time, with the 5th hopefully soon.

Compare to 47 years for C, or 29 for Python, I imaging the early versions
were also clunky.



-----
Admin - email* me if you need anything, or if I've done something stupid...

* click on my MichaelAtOz label, there is a link to email me.

Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above.

The TPP is no simple “trade agreement.”   Fight it! http://www.ourfairdeal.org/   time is running out!
--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Admin - email* me if you need anything,
or if I've done something stupid...
* click on my MichaelAtOz label, there is a link to email me.

Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work.
Obviously inclusion of works of previous authors is not included in the above.


The TPP is no simple “trade agreement.” Fight it! http://www.ourfairdeal.org/ time is running out!
Reply | Threaded
Open this post in threaded view
|

Re: Learning how to use OpenSCAD

JordanBrown
In reply to this post by adrianv
On 2/20/2019 11:32 AM, adrianv wrote:
JordanBrown wrote
On 2/20/2019 4:59 AM, adrianv wrote:
Of course one can say you learn what you need to in order to make the
design
you're trying to make.  But it wasn't apparent to me, for example, the
way
that modules could use children and what (some of) the implications are.

Have you read this tutorial?

http://www.tridimake.com/2014/09/how-to-use-openscad-tricks-and-tips-to.html

It covers children in section 4.
Yes.  That tutorial was what opened my eyes to this whole capability.  But I
had to stumble across it.

If you go to openscad.org, then "documentation", then (in the left sidebar or scroll down), "Tutorials - Articles / Blogs", it's the first link.  It was the first thing I saw and read.  It could be more prominent, but not much.

It also raises the question about applying my own
module to a loop when they describe how their chained_hull() module won't
work on the output of for(), since for() just produces one child.   That's
what caused me to ask the question about whether I can write my own for()
function.  Certainly the code example where he hard codes the wedge_if calls
in a big list seems pretty darn ugly.  Is that the best that is possible? 
It seems like being able to write my own iteration, or to operate on the
separate children of a for loop, would be a useful feature.  I assume
there's some reason it missing.  It is impossible, right?

As nop head said, a module can only return one child.

Note: I recognize what can be done with matrix transformations.  I'm just
not seeing (at the moment) an application for it.  And if it's only good for
making skews, really, then it seems like you really just want to write the
skew() module and never look at mulmatrix again, due to its increased
complexity.

Other than general DIY matrixes, skewing is the only application I know of.  Indeed, I wrote a skew module to wrap it.  I haven't thought enough about it to know whether one function is enough, or if you need more than one.  If you try to do it with only one, I suspect that you end up having to pass six values to fully describe the skew.  (But non-trivial skews hurt my brain.)

I suspect that much of the reason for it is that the other functions require the capability, so why not expose it in case somebody finds it useful?

I saw in another message somebody searching vertex lists with search() for
some purpose that I didn't fully understand.  Lookup tables on single
characters seems like a pretty contrived example.  

Well... it *was* the answer to a question that somebody really asked, so not totally contrived.  I don't remember exactly what they were looking for, but it involved getting character spacing right.  (A further enhancement along the same lines might do searches on character pairs for kerning.)

I have used the somewhat-similar lookup( ) in my own work to do interpolated lookups in a table.



_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Learning how to use OpenSCAD

lostapathy
In reply to this post by MichaelAtOz
On 2/20/19 4:45 PM, MichaelAtOz wrote:
lostapathy wrote
OpenSCAD has a weird relationship with libraries. 
1)  No package manager has ever really gained much adoption

2)  There's not a lot of community knowledge on how to make a library 
3)  The language needs additional features to better support libraries. e.g.
Namespaces

There has been much discussion on the future direction of OpenSCAD including
many such features, see  here
<https://github.com/openscad/openscad/wiki/OpenSCAD-Enhancement-Proposals>  
&  here <https://github.com/doug-moen/openscad2/blob/master/README.md>   for
example, plus much past discussion in the headspace of the development
community. Note that they are proposals and still need design work (IMHO)
and not necessarily fully endorsed direction.
I'm quite familiar with that discussion at the info on GitHub.

I'm not saying there isn't room for language improvement, but IME you can go a long on libraries without namespaces.  The scoping difference of include vs use makes it possible to not pollute the namespace with extra variables  or modules.  Libraries can be built such that a use'd file only puts one module into the namespace of the caller, so you can import only a minimum amount of functionality.  Given that, I'm not sure why calling a module as MyLibrary-Function() vs MyLibrary::Function() is a show stopper.


But as Hugo mentions, there is only a small pool of spare-time developers,
the resources available vary, so progress has to go in baby steps. An
unfortunate reality.

I agree completely.  My point was that if we build up the userspace ecosystem around OpenSCAD to enable a larger user base, the small subset of OpenSCAD users who can also develop on OpenSCAD itself will probably grow with the community.




_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Learning how to use OpenSCAD

adrianv
In reply to this post by lostapathy
I hadn't thought about the possible importance of having a package manager.  
It looks like your project is a reasonable effort.  I'm not sure it's enough
alone.  To me it seems like the thing that will make packages successful is
a central authority that lists packages (so people can find them) and
documentation and tutorials about the packages.  This last thing is crucial.
There is a list of packages in the manual, but the list is not very useful
because it doesn't state what exactly the packages can (or cannot) do.  And
furthermore, the packages aren't well documented.  And it comes across more
like a random collection of assorted code people wrote than an organized
extension to OpenSCAD.  If a package is seen as a standard library you
should be able to find documentation about how to use it and what it does.
If you look up the C++ template classes, or NumPy, you don't have to read
the source code to figure out what they can do or how to use them.   The
package are documented right along side the basic language.  If the OpenSCAD
manual had a section on packages and actually documented them, then new
users would presumably be interested in getting and using the packages.  I
updated my OpenSCAD from what is apparently the stable version (???) from 3
years ago to the development version because I read the manual and needed
those features.  If I read about some package that would solve my problem
I'd install it.  But there's nothing to read about....  

I tried to use path_extrude on my recent project but had problems.  Lack of
documentation made it unclear if they were solvable or not.  Maybe I should
read the code.  But looking at it now, I see that it starts at the ground
level, defining lots of very primitive operations that one might imagine
should be supplied in some standard way by lower level packages.  

I think this also ties to the second point.  If there are no libraries
designed for reuse then it's hard for users to know how to write such a
library.  What I stumbled across were various piles of code that may (or may
not) be well designed code.  I don't know.  And I'm not sure what they do.
Where is my model for how to make a library?  If I had example libraries
that were well documented it would provide ideas about how to design
additional libraries, I think.   It also seems like there's a potential
issue with libraries including other libraries.  Is it bad for a library to
be included multiple times in different scopes?  

The "post your library on thingiverse" approach seems ridiculous to me.  I
started running across stuff on thingiverse and it wasn't clear to me what
its status was.   It's not where I'd expect to find a library---that's for
sure.  

I'm not sure what the solution is---and obviously I just popped in here
today so I'm not really in a position to say what should happen.  But it's
seeming more and more like the existing situation is problematic.  Perhaps
we should start a well defined project of some kind to establish and
document a set of standard libraries?  


lostapathy wrote

> OpenSCAD has a weird relationship with libraries.  I think there's
> fundamentally 2 problems that feed each other.
>
> 1)  No package manager has ever really gained much adoption. (I've tried
> - I'm the author of https://github.com/lostapathy/scad_bundler).  Which
> probably makes sense because there aren't many libraries packaged for
> any package manager.
>
> 2)  There's not a lot of community knowledge on how to make a library
> that is well suited for reuse (or extract one from a larger project).
>
> There's definitely a bootstrapping problem here.  I personally think a
> lot of the perceived limitations of OpenSCAD can be solved at the
> library level, and having a more compelling ecosystem there will attract
> more effort in OpenSCAD itself.
>
> I haven't spent much time on scad_bundler recently because I never got
> much interest or engagement on it - good bad or otherwise. Perhaps
> there's a mismatch in that I'm trying to approach using OpenSCAD like a
> software engineering problem, and maybe that's not where the community
> is at.  At the same time, "post your library on thingiverse" hasn't
> really taken off, either.
>
> I'm not sure what the next step is, but I'm open to suggestions.





--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Learning how to use OpenSCAD

boxcarmib
In reply to this post by MichaelAtOz
I suggest that a useful first step might be legitimizing what libraries are currently available by adding them to the OpenSCAD User Manual… as say Chapter 10. That way at least those are aren’t adverse to RTFM would see that libraries are not simply routines of unknown providence showing up on Thingiverse.
If there’s support for this first step I’d be happy to start said Chapter 10 and populating it with what I can gather from the existing library code.

> On Feb 20, 2019, at 2:45 PM, MichaelAtOz <[hidden email]> wrote:
>
> lostapathy wrote
>> OpenSCAD has a weird relationship with libraries.
>> 1)  No package manager has ever really gained much adoption
>>
>> 2)  There's not a lot of community knowledge on how to make a library
>
> 3)  The language needs additional features to better support libraries. e.g.
> Namespaces
>
> There has been much discussion on the future direction of OpenSCAD including
> many such features, see  here
> <https://github.com/openscad/openscad/wiki/OpenSCAD-Enhancement-Proposals>  
> &  here <https://github.com/doug-moen/openscad2/blob/master/README.md>   for
> example, plus much past discussion in the headspace of the development
> community. Note that they are proposals and still need design work (IMHO)
> and not necessarily fully endorsed direction.
>
> But as Hugo mentions, there is only a small pool of spare-time developers,
> the resources available vary, so progress has to go in baby steps. An
> unfortunate reality.
>
> It should also be noted that OpenSCAD is young, according to Wikipedia, the
> initial release was 19 February 2010. Happy 9th Birthday!! And only really 4
> major releases in that time, with the 5th hopefully soon.
>
> Compare to 47 years for C, or 29 for Python, I imaging the early versions
> were also clunky.
>
>
>
> -----
> Admin - email* me if you need anything, or if I've done something stupid...
>
> * click on my MichaelAtOz label, there is a link to email me.
>
> Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above.
>
> The TPP is no simple “trade agreement.”   Fight it! http://www.ourfairdeal.org/   time is running out!
> --
> Sent from: http://forum.openscad.org/
>
> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Learning how to use OpenSCAD

adrianv
boxcarmib wrote
> I suggest that a useful first step might be legitimizing what libraries
> are currently available by adding them to the OpenSCAD User Manual… as say
> Chapter 10. That way at least those are aren’t adverse to RTFM would see
> that libraries are not simply routines of unknown providence showing up on
> Thingiverse.
> If there’s support for this first step I’d be happy to start said Chapter
> 10 and populating it with what I can gather from the existing library
> code.

This sounds like a great idea.  The only question I have---having not
examined the libraries in question---is whether they are good libraries.  Is
the API well thought out.  I don't want to put up roadblocks to progress,
but you want to get things off to a good start.      




--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Learning how to use OpenSCAD

boxcarmib
As per this discussion I’ve been spending the afternoon looking at the existing libraries and I would say they are of mixed quality, so part of the work I’d be willing to undertake would be to refactor most of them, and subject their modification to whatever the general review process is for code enhancements.
There are a number of libraries that really should be folded together… there’s a least 3 “shape” libraries, some of which have overlapping functionally, and some that have modules that just don’t work, not to mention libraries that haven’t been worked on in years so they bring up “assign deprecated” and other similar errors.
 I’ve used source control in many forms but not GitHub and I don’t know what the protocol and procedures would be for submitting proposed changes and the release mechanism, so I’d need a little handholding help with that… perhaps there’s some already overworked code developer maintainer who could shoot me an offer to help me get bootstrapped into “how to submit changes to the OpenSCAD master branch”.

> On Feb 20, 2019, at 4:19 PM, adrianv <[hidden email]> wrote:
>
> boxcarmib wrote
>> I suggest that a useful first step might be legitimizing what libraries
>> are currently available by adding them to the OpenSCAD User Manual… as say
>> Chapter 10. That way at least those are aren’t adverse to RTFM would see
>> that libraries are not simply routines of unknown providence showing up on
>> Thingiverse.
>> If there’s support for this first step I’d be happy to start said Chapter
>> 10 and populating it with what I can gather from the existing library
>> code.
>
> This sounds like a great idea.  The only question I have---having not
> examined the libraries in question---is whether they are good libraries.  Is
> the API well thought out.  I don't want to put up roadblocks to progress,
> but you want to get things off to a good start.      
>
>
>
>
> --
> Sent from: http://forum.openscad.org/
>
> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
12