I am trying to do something in a function one of n ways (in this case one of four ways).
First I tried doing a ternary operator nested twice (but it didn't seem to like the syntax) and then I tried if statements. If I have a function and what it does is dependent on a variable with n possible values, is there some way to do it inside that function? What I did in the past was to use the ternary operator once per helper but this gets fairly tedious (it is easier to read but cumbersome). I have an example where I tried to use "if" statements inside the function (but it didn't work). Likewise nesting ternary operators inside that function didn't work. I'd prefer not to create 6 helper functions (two that use the ternary operator to decide which of the four end functions to use) function computeAngle(number, quadrant) = let(baseAngle = atan(2/(number1)) if (quadrant == 1) { baseAngle; } else if (quadrant == 2) { 180  baseAngle; } else if (quadrant == 3) { 180 + baseAngle; } else { 360  baseAngle; } } _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org 
20180207 18:52 GMT02:00 Dan Shriver <[hidden email]>:
_______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org 
In reply to this post by DanS
I've taken to doing something like:
(quadrant==1)? ... :(quadrant==2)? ... :(quadrant==3)? ... ://(quadrant=4) ... ; Which seems to work just fine.  Sent from: http://forum.openscad.org/ _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org 
If you can also just use quadrant as array index:
function computeAngle(number, quadrant) = let(baseAngle = atan(2/(number1))) [ baseAngle, 180  baseAngle, 180 + baseAngle, 360  baseAngle ][quadrant  1]; ciao, Torsten. _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
 Torsten

Free forum by Nabble  Resume Templates  Edit this page 