Thursday, October 27, 2016

Custom Looping Function Template in OpenSCAD

SOURCE BELOW, and here as paste-bin snippet: http://pastebin.com/UEnQCTEe

Any function you can write in javascript, you can write in openSCAD. (Note, it might be hacky and inefficient, but you can do it.)

Here is my template for when I need to convert an imperative for-loop into a functional programming style supported by openSCAD function syntax.

data = recursiveLoop(0,9,[]);
echo(data); //Output==> ECHO:[0,1,2,3,4,5,6,7,8,9]

function recursiveLoop(os, num_pts, data_out)=
(
    os <= num_pts
    ?
    recursiveLoop_WORK_DETOUR(os, num_pts, data_out)
    :
    data_out
);

function recursiveLoop_WORK_DETOUR(os, num_pts, data_out)=
(
    recursiveLoop
    (
        os+1, num_pts, ( concat(data_out,os) )
    )
);

Sunday, October 16, 2016

Point-Normal Line Collision Code

Here is the source: ------------------------------------------------------ Point-Normal Line Collision : JavaScript Source: http://pastebin.com/DvjwA67g Point-Normal Line Collision : JavaScript for OpenScad: http://pastebin.com/94aWgT8U Point-Normal Line Collision : OpenScad Code: http://pastebin.com/azXb7hhc ------------------------------------------------------ Point-Normal Line Collision Code. Takes two lines in point-normal form and sees where they intersect. Also tells you which segments the collisions exist on. Where the length of each segment is defined by the length of the NON-NORMALIZED vector input. There is probably a better name for what I did. Seeing that I couldn't find the answer to this on the internet.