discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Re: if then else - possible

Jan Öhman
Thu, Apr 21, 2022 9:06 PM

I found the solution==========        startAngel  = (startRef == "left")   ?   0                    : (startRef == "bottom") ?  90                    : (startRef == "right")  ? 180                    : (startRef == "top")    ? 270                    : startRef,

Den torsdag 21 april 2022 20:56:09 CEST, Jan Öhman via Discuss <discuss@lists.openscad.org> skrev:  

Hi!
I have a function() where the input values are normally "top" / "bottom" and so on.which in turn results in degrees like this example

function(... , startRef="bottom", ...)     let(        startAngel  = (startRef == "left")   ?   0                    : (startRef == "bottom") ?  90                    : (startRef == "right")  ? 180                    : (startRef == "top")    ? 270                    : undef,        r = radius,
===========Now if the variable is not "left", "bottom" etc.the startAngle value is "undef"
it works, but it happens that I would like to be able to enter degrees as a reference value.
something like
==========        startAngel  = (startRef == "left")   ?   0                    : (startRef == "bottom") ?  90                    : (startRef == "right")  ? 180                    : (startRef == "top")    ? 270                    : startRef == startRef==========
Is it possible? (the last example doesn't work)

The whole function() looks like this:==========
points = circSect(0, 0, 25, [-45, 45], "top", 1, 100);polygon(points);
//

---================//======  circleSect 
---=============================// Create rounded corners 2D// https://openhome.cc/eGossip/OpenSCAD/SectorArc.html// ange .:  x, y, radien,//          [från, till] vinkel,//          var vinkeln startar, (left, bottom, right, top)//          vilken rotation (-1=medsol, 1=motsols)function circSect(x=0, y=0, radius=10, angles=[0,270], startRef="bottom", rotate=1, fn=24)  =    let(        startAngel  = (startRef == "left")   ?   0                    : (startRef == "bottom") ?  90                    : (startRef == "right")  ? 180                    : (startRef == "top")    ? 270                    : undef,        r = radius,        //r = radius / cos(180 / fn),        step = 360 / fn,        // points = [[x, y],        points = [            for(a = [angles[0]-startAngel : step : angles[1]-startAngel])                [-rotate * r * cos(a)+x, r * sin(a)+y]]    ) points;//========  Slut circleSect 
---======================


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

I found the solution==========        startAngel  = (startRef == "left")   ?   0                    : (startRef == "bottom") ?  90                    : (startRef == "right")  ? 180                    : (startRef == "top")    ? 270                    : startRef, Den torsdag 21 april 2022 20:56:09 CEST, Jan Öhman via Discuss <discuss@lists.openscad.org> skrev: Hi! I have a function() where the input values are normally "top" / "bottom" and so on.which in turn results in degrees like this example ========== function(... , startRef="bottom", ...)     let(        startAngel  = (startRef == "left")   ?   0                    : (startRef == "bottom") ?  90                    : (startRef == "right")  ? 180                    : (startRef == "top")    ? 270                    : undef,        r = radius, ===========Now if the variable is not "left", "bottom" etc.the startAngle value is "undef" it works, but it happens that I would like to be able to enter degrees as a reference value. something like ==========        startAngel  = (startRef == "left")   ?   0                    : (startRef == "bottom") ?  90                    : (startRef == "right")  ? 180                    : (startRef == "top")    ? 270                    : startRef == startRef========== Is it possible? (the last example doesn't work) The whole function() looks like this:========== points = circSect(0, 0, 25, [-45, 45], "top", 1, 100);polygon(points); //==================================================================================//======  circleSect  ==============================================================// Create rounded corners 2D// https://openhome.cc/eGossip/OpenSCAD/SectorArc.html// ange .:  x, y, radien,//          [från, till] vinkel,//          var vinkeln startar, (left, bottom, right, top)//          vilken rotation (-1=medsol, 1=motsols)function circSect(x=0, y=0, radius=10, angles=[0,270], startRef="bottom", rotate=1, fn=24)  =    let(        startAngel  = (startRef == "left")   ?   0                    : (startRef == "bottom") ?  90                    : (startRef == "right")  ? 180                    : (startRef == "top")    ? 270                    : undef,        r = radius,        //r = radius / cos(180 / fn),        step = 360 / fn,        // points = [[x, y],        points = [            for(a = [angles[0]-startAngel : step : angles[1]-startAngel])                [-rotate * r * cos(a)+x, r * sin(a)+y]]    ) points;//========  Slut circleSect  ======================================================= _______________________________________________ OpenSCAD mailing list To unsubscribe send an email to discuss-leave@lists.openscad.org