building flat array with successive functions and tests in functions....

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

building flat array with successive functions and tests in functions....

bboett
Hello!

on the path to more complexity i hit another wall:

in roundPoint i can't add the test? it gives me a syntax error in  front of the for loop?

and the main problem, i can't feed this to a polygon, each function adds a nesting to the produced array, how do i avoid this?

my son had the ... delightful.... idea of drawing a dragon, so i started on something to build the beak of it... i begun to draw the rough shape , and once having that shape i wanted to smooth it out, but it didn't work as i supposed it would...

thanks for any help!
Bruno




echo("poly",  kieferPoly(b  =40,l = 70,lw=10, d=2)) ;


function baseForm(x, b, l) = (b!= 0)? 4*l/(b*b) *x*x - l:0;
function curveAngle(l, y0, ueber, lw,hprim) =  (l+y0 <= ueber)? 105-2*lw - atan((ueber -y0)/hprim):(y0 == 0)? 0:-atan(y0/hprim);

function roundPoint(pt,rad, res = 3,above = true) =
[
//(above == true)?
       for(n = [0:1:res])
           let (w = 180 + 180/res*n)
             [pt[0]+rad*cos(w),pt[1], pt[2]+rad*sin(w)]    
// :
//        for(n = [0:1:res])
//            let (w = 180/res*n)
//              [pt[0]+rad*cos(w),pt[1], pt[2]+rad*sin(w)]    
];

function transvCut(x,y,z,d=1,res=3) =
[
  roundPoint([x,y,z],d,res),
  roundPoint([0,y,z+x],d,res, above = 0),          
  roundPoint([-x,y,z],d,res)
];

function kieferPoly(b,l,lw=10, d=2) =
let(curve = sqrt(l*l+ b*b/4))
let(hprim = curve*cos(lw))
let(  ueber = curve*sin(lw))
[
  for(x = [-b/2: 1 : 0])
    let(y0 = baseForm(x,b,l))
    let(beta = curveAngle(l, y0, ueber, lw,hprim))
    transvCut(x,y0,curve*cos(beta)-hprim,d),
];



--
ciao
Bruno

===========================================
http://nohkumado.eu/, http://aikido.nohkumado.eu/,
http://aikido.zorn.free.fr

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

Re: building flat array with successive functions and tests in functions....

tp3
Yes, the list comprehension is not a general expression.
I'm not sure it's possible to change that.

Both branches look the same anyway, so I'd use

w = 180/res*n + above ? 180 : 0

As for nesting, check this post:
http://forum.openscad.org/2D-SVG-concat-points-point-no-output-loops-amp-conditionals-vector-declarations-td29068.html#a29070

You can drop one nesting level using 'each'

For some extra ideas for drawing using math, check
out https://www.desmos.com/art

ciao,
  Torsten.

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

Re: building flat array with successive functions and tests in functions....

doug.moen
In reply to this post by bboett
You can't use a a?b:c conditional within a list comprehension. You must use if (a) b else c instead.
Try replacing the list comprehension with this:

[
  if (above == true)
       for(n = [0:1:res])
           let (w = 180 + 180/res*n)
             [pt[0]+rad*cos(w),pt[1], pt[2]+rad*sin(w)]    
  else
       for(n = [0:1:res])
           let (w = 180/res*n)
             [pt[0]+rad*cos(w),pt[1], pt[2]+rad*sin(w)]    
];


Doug Moen.


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

Re: building flat array with successive functions and tests in functions....

bboett
thanks , that worked indeed!

Am Do., 21. Mai 2020 um 22:51 Uhr schrieb Doug Moen <[hidden email]>:
You can't use a a?b:c conditional within a list comprehension. You must use if (a) b else c instead.
Try replacing the list comprehension with this:

[
  if (above == true)
       for(n = [0:1:res])
           let (w = 180 + 180/res*n)
             [pt[0]+rad*cos(w),pt[1], pt[2]+rad*sin(w)]    
  else
       for(n = [0:1:res])
           let (w = 180/res*n)
             [pt[0]+rad*cos(w),pt[1], pt[2]+rad*sin(w)]    
];


Doug Moen.

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


--
ciao
Bruno

===========================================
http://nohkumado.eu/, http://aikido.nohkumado.eu/,
http://aikido.zorn.free.fr

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

Re: building flat array with successive functions and tests in functions....

bboett
In reply to this post by tp3
great! each solved the stuff!
thanks!

Am Do., 21. Mai 2020 um 20:56 Uhr schrieb Torsten Paul <[hidden email]>:
Yes, the list comprehension is not a general expression.
I'm not sure it's possible to change that.

Both branches look the same anyway, so I'd use

w = 180/res*n + above ? 180 : 0

As for nesting, check this post:
http://forum.openscad.org/2D-SVG-concat-points-point-no-output-loops-amp-conditionals-vector-declarations-td29068.html#a29070

You can drop one nesting level using 'each'

For some extra ideas for drawing using math, check
out https://www.desmos.com/art

ciao,
  Torsten.

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


--
ciao
Bruno

===========================================
http://nohkumado.eu/, http://aikido.nohkumado.eu/,
http://aikido.zorn.free.fr

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