├── README.md └── snippets.md /README.md: -------------------------------------------------------------------------------- 1 | # OpenSCAD Tips 2 | 3 | #### Menu 4 | | [**Official**](#official_help) | [**tips**](#tips) | [**My_libs**](#my_libs) | [**Tools**](#tools) | [**Libs**](#libs) | [**Lib_systems**](#lib_systems) | [**OpenSCAD_variations**](#openscad_variations) | [**Other_cads**](#other_cads) | [**Other_Drawing_programs**](#other_drawing_programs) | [**Inspiration**](#inspiration) | [**Subdivision**](#subdivision) | [**References**](#references) | 5 | 6 | ### Official_help 7 | * [OpenSCAD language ref](https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/The_OpenSCAD_Language) 8 | * Cheet sheet: [Official](http://www.openscad.org/cheatsheet/), [KitWallace's](http://kitwallace.co.uk/openscad/OpenSCAD%20CheatSheet.htm) 9 | * [Work in Progress](https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/WIP) 10 | * [Nightly snapshots](http://files.openscad.org/snapshots/) 11 | * [OpenSCAD forum](http://forum.openscad.org) 12 | * [OpenSCAD freenode IRC](http://webchat.freenode.net/?channels=#openscad) 13 | * [OpenSCAD Libraries location](https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Libraries) 14 | 15 | ==> [Edit](https://github.com/runsun/OpenSCAD_Tips/edit/master/README.md) | [Menu](#menu) 16 | 17 | ### Tips 18 | * [animation](http://forum.openscad.org/About-animation-just-for-the-record-just-for-Windows-users-td16733.html) ( [gif](http://forum.openscad.org/Animating-gif-with-3D-rotation-tp14011.html), [prodVid](http://forum.openscad.org/Product-Video-produced-with-OpenSCAD-td15783.html), [animlib](http://forum.openscad.org/Animation-Motion-Library-td17196.html), [imgsize](http://forum.openscad.org/Can-I-force-Animation-to-use-quot-Render-quot-instead-of-quot-Preview-quot-td14828.html#a14848), [JordanBrown](http://forum.openscad.org/matrix-interpolation-td22284.html)) 19 | * [area](http://forum.openscad.org/Easy-way-to-get-the-area-of-a-polygon-tp17045p17055.html) 20 | * Associated Array: See hash below 21 | * Bazier [Ronaldo's 3D Bezier patch](http://forum.openscad.org/Can-you-sweep-a-object-with-fingers-tp19057p19309.html), [nophead's subdivision3](http://forum.openscad.org/OpenSCAD-programming-question-recursion-functions-and-modules-tp23197p23217.html), Eric Buijs' [PolyBeziers](https://plus.google.com/104802930025458639218/posts/VZrXMxLd8Mt), [NateTG's n-Bezier](http://forum.openscad.org/making-vases-perhaps-with-InkScape-tp23301p23329.html)([his Correction](http://forum.openscad.org/making-vases-perhaps-with-InkScape-tp23301p23335.html)), [Revar Desmera's BOSL](https://github.com/revarbat/BOSL/wiki/beziers.scad), [WilliamAAdam's bezier.scad](https://www.thingiverse.com/thing:8483/files), [OpenHome's bezier_smooth](https://openhome.cc/Gossip/OpenSCAD/lib-bezier_smooth.html) 22 | * Bounding box (1) [doc](https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Commented_Example_Projects) handles only one obj; (2) [Ronaldo](http://forum.openscad.org/Round-anything-Retrospective-rounding-filleting-module-tp21794p21820.html) handles one or more; (3) [Ronaldo's 2d](http://forum.openscad.org/Getting-2D-bounding-box-dimensions-td23256.html); (4) [blobule](https://www.bountysource.com/issues/218729-functions-that-can-query-a-given-3d-shape-and-provide-size-or-location-info) 23 | * [Chinese font](http://forum.openscad.org/How-to-write-a-texture-to-a-face-Solid-in-a-geometric-model-tp16718p16753.html) 24 | * color/HTML color: [MichaelAtOz](https://github.com/openscad/openscad/files/1250754/rgb.txt) 25 | * Commandline [Enable Exp Features](http://forum.openscad.org/Enable-experimental-features-concat-text-in-command-line-td9287.html#a9290), [Set parameters and rotation](http://forum.openscad.org/Animating-gif-with-3D-rotation-td14011.html#a14029) 26 | * [Curved Image](http://forum.openscad.org/Images-on-curved-cylindrical-surface-td17823.html) 27 | * Curve Text: [JustinSDK](http://openhome.cc/eGossip/OpenSCAD/ModifierCharacters.html), [MichaelAtOz](http://forum.openscad.org/textCylinder-dodgy-version-for-text-around-a-cylinder-td9262.html#a9265) 28 | * Degenerate polygon [Ronaldo](http://forum.openscad.org/Polyhedron-degenerated-triangles-are-allowed-but-quads-td19917.html) 29 | * Data Structure [NateTG's 2-3 tree](http://forum.openscad.org/Programming-in-Functional-OpenSCAD-td23039.html), [Good 2-3 ref](http://cs.wellesley.edu/~cs230/fall02/2-3-trees.pdf), [thehans' L-system](http://forum.openscad.org/L-systems-demo-Fractal-designs-interpreter-performance-stress-testing-td23295.html)([github](https://gist.github.com/thehans/a1494db8046a58832e2ebb10a5908a66)) 30 | * Dimensioning: Don Smiley's dimlines: [new ver](http://forum.openscad.org/Dimension-Parameter-labeling-for-part-diagrams-tp15172p15185.html), [doc](http://www.cannymachines.com/entries/9/openscad_dimensioned_drawings) 31 | * Editor ([Quick ref on browser by Len Trigg](http://forum.openscad.org/Poor-mans-quick-help-lookup-for-openscad-built-in-modules-td23242.html)) 32 | * [excel-control](http://forum.openscad.org/Parameterlist-Excel-export-to-OpenSCAD-tp15363p15367.html) 33 | * Flatten surface: [nophead's](http://forum.openscad.org/flattening-curved-surfaces-tp19727p19763.html), [runsun's](http://forum.openscad.org/flattening-curved-surfaces-tp19727p19782.html), [osresearch papercraft](https://github.com/osresearch/papercraft), [Parkinbot's](http://forum.openscad.org/flattening-curved-surfaces-tp19727p19807.html) 34 | * [$fa,$fs,$fn](http://forum.openscad.org/better-than-fn-get-fs-working-a-tutorial-td1271.html), [1](http://forum.openscad.org/fn-fa-and-fs-tp17932p17936.html),[Ian](https://forum.makehackvoid.com/t/openscad-circle-calculations/721) 35 | * [gear](http://lcamtuf.coredump.cx/gcnc/ch6/#6.1), [Parkinbot](http://www.thingiverse.com/thing:636119), [discussion](http://forum.openscad.org/Question-about-gear-library-td25035.html) 36 | * Geodisc [William Adams](https://www.thingiverse.com/thing:10725),[2](https://www.thingiverse.com/thing:10540), [Yona Appletree](https://gist.github.com/Yona-Appletree/a03bc32a5c5ca6886e38) 37 | * hash: [1](http://forum.openscad.org/parameterized-models-td8303.html#a8306), [2](http://forum.openscad.org/Can-I-get-some-code-review-up-in-here-tp12341p12355.html), [Search-based hash](http://www.thingiverse.com/groups/openscad/topic:5610#comment-1093645) 38 | * Hermite interpolation [Ronaldo's](http://forum.openscad.org/making-vases-perhaps-with-InkScape-tp23301p23352.html) 39 | * [isosphere](http://forum.openscad.org/New-Algorithm-for-Spheres-tp13306p17062.html)([2](http://blog.andreaskahler.com/2009/06/creating-icosphere-mesh-in-code.html)) 40 | * [lerp](http://forum.openscad.org/Irregular-mesh-generated-tp13765p13779.html ) 41 | * [Lazy Union by Parkinbot](http://forum.openscad.org/rendering-for-paper-assembly-manual-tp20108p20126.html), [Ronaldo's](http://forum.openscad.org/rendering-for-paper-assembly-manual-tp20108p20140.html) 42 | * Loft: [Marko's excellent code](http://forum.openscad.org/Sweeping-polygon-over-irregular-shape-tp24801p24880.html) 43 | * [makefile](http://forum.openscad.org/Makefile-for-building-complex-models-from-a-single-file-td22296.html ) 44 | * [matrix](http://www.thingiverse.com/thing:10249/#files)([2](http://forum.openscad.org/restrict-hull-function-to-one-or-two-dimensions-tp16696p16722.html),[3](https://github.com/lhartmann/openscad_m4lib/blob/master/m4.scad)); [invert](https://github.com/openscad/openscad/issues/1040#issuecomment-233208606) 45 | * Packaging: [1](http://forum.openscad.org/Managing-libraries-and-modules-in-complex-projects-td23200.html), [OpenSCAD-Modules by RobertFach](http://forum.openscad.org/A-Package-Manager-for-OpenSCAD-td23465.html) 46 | * Parser for OpenSCAD: [runsun's re_utils.py](https://bitbucket.org/runsun/py_re_utils/src/37b20287b338738dcf35635b3b310595a60fb76b/re_utils.py?at=master&fileviewer=file-view-default), [Hornbacher's node-scad-parser (node.js)](https://github.com/hhornbacher/node-scad-parser), [FreeCAD's (py)](https://github.com/jreinhardt/FreeCAD_sf_master/tree/master/src/Mod/OpenSCAD), [OpenSCAD's core parser.y](https://github.com/openscad/openscad/blob/master/src/parser.y), [Josef Prusa's thingdoc(py)](https://github.com/josefprusa/ThingDoc/blob/master/thingdoc) 47 | * Parser in OpenSCAD: [runsun's scadx_match](https://bitbucket.org/runsun/scadx/src/f144a5d77e534ae81d712e41bd5e89d8a8629ab4/scadx_match.scad?at=master&fileviewer=file-view-default), [Parkinbot's stl parser](http://forum.openscad.org/flattening-curved-surfaces-tp19727p19816.html), [APruss' Function parser](https://www.thingiverse.com/thing:2295309), [Carl Davidson's string.scad](https://www.thingiverse.com/thing:526023)([git](https://github.com/davidson16807/relativity.scad/blob/master/strings.scad)) 48 | * [precision](http://forum.openscad.org/Inconsistent-conversion-of-floating-number-to-string-at-7th-significant-digit-tp14350.html)([2](http://forum.openscad.org/Simple-addition-of-numbers-introduces-error-td14408.html)) 49 | * render() to display massive objs: [nophead](http://forum.openscad.org/Profiling-of-hull-and-cylinder-based-line-drawings-tp25189p25225.html), [tp3's example](http://forum.openscad.org/too-many-hexagons-crashes-openscad-how-many-is-too-many-tp24711p24713.html) 50 | * [RGB](http://forum.openscad.org/An-HSV-HSB-to-RGB-Color-function-in-OpenSCAD-td9835.html) 51 | * Round Anything by [irev dev](https://www.thingiverse.com/thing:2419664) 52 | * Rounded Cube [Parkinbot](http://forum.openscad.org/Functional-OpenSCAD-working-with-vertex-data-tp21080p23072.html), [Parkinbot new](http://forum.openscad.org/Functional-OpenSCAD-working-with-vertex-data-tp21080p23064.html) 53 | * [rounded polygon](http://forum.openscad.org/Script-to-replicate-hull-and-minkoswki-for-CSG-export-import-into-FreeCAD-td16537.html) 54 | * Search(): [details](http://forum.openscad.org/Digging-into-search-td12421.html) 55 | * Shelling: [jweoblog](http://jweoblog.com/?p=644) 56 | * Sphere [berkenb's ssphere](http://forum.openscad.org/Coating-a-sphere-with-bumps-golf-ball-ish-for-wheel-treads-tp24090p24094.html), [runsun's spherePF](https://github.com/runsun/OpenSCAD_Tips/blob/master/snippets.md#sphere), [1](http://forum.openscad.org/New-Algorithm-for-Spheres-td13306.html#a17087), [Jamie Kawabata's geodesic sphere](https://www.thingiverse.com/thing:1484333), [thehans' alternative sphere](https://github.com/thehans/FunctionalOpenSCAD/blob/master/alternative_spheres.scad) 57 | * Spline [1](http://forum.openscad.org/Modelling-a-flexible-strip-td22645.html) 58 | * Spring: [Parkinbot](http://forum.openscad.org/how-to-make-the-groove-more-width-tp20154p20158.html) 59 | * Sweeping: [Marko's excellent code](http://forum.openscad.org/Sweeping-polygon-over-irregular-shape-tp24801p24880.html), [sweep.scad](https://github.com/openscad/list-comprehension-demos/blob/master/sweep.scad) ([1](http://forum.openscad.org/Two-annoyances-td12935i20.html#a13110),[2](http://forum.openscad.org/Vertex-arrays-tp15876p15969.html),[3](http://forum.openscad.org/file/n18324/sweep2.scad)), [Benjemin Easing Func](http://forum.openscad.org/Sweep-with-easing-equations-td20075.html), [Parkinbot's twisted vase](http://forum.openscad.org/making-vases-perhaps-with-InkScape-tp23301p23324.html) 60 | * [tail Recursion](http://forum.openscad.org/Simple-polygon-triangulation-tp16755p16941.html)([2](http://forum.openscad.org/Simple-polygon-triangulation-tp16755p16962.html),[3](http://forum.openscad.org/Tail-recursion-td17040.html),[4](http://forum.openscad.org/Simple-polygon-triangulation-tp16755p16941.html)) 61 | * [text](http://forum.openscad.org/Wrapping-text-around-a-complex-geometry-tc18145.html), [Carl Davidson's str lib](https://www.thingiverse.com/thing:526023), [Chambered](http://forum.openscad.org/Chamfered-3D-text-td23162.html) 62 | * testing: [tests in OpenSCAD](http://forum.openscad.org/Clarifying-behaviors-tp18492p18507.html)([2](http://forum.openscad.org/tests-in-OpenSCAD-td8978.html),[Regression test](https://github.com/openscad/openscad/blob/master/doc/testing.txt)), [RoyaSutton](http://forum.openscad.org/Doxygen-openscad-amu-and-omdl-Documenting-and-Design-Flow-td19924.html)([pdf](https://cdn.thingiverse.com/assets/3c/16/d2/00/ea/refman.pdf)), [runsun's doctest](https://github.com/runsun/openscad_doctest) 63 | * Triangulation: [Ronaldo](http://forum.openscad.org/Polyhedron-tube-with-irregular-sides-is-it-possible-tp13813p25151.html) , [forum](http://forum.openscad.org/Simple-polygon-triangulation-td16755.html), [Parkinbot](http://forum.openscad.org/Simple-polygon-triangulation-tp16755p16837.html), [NateTG's](http://forum.openscad.org/making-vases-perhaps-with-InkScape-tp23301p23395.html), [NateTG's 2](https://gist.github.com/NateTG/b350378c56f436d3996a2107f7cba965) 64 | * Tube: [Ronaldo's](http://forum.openscad.org/file/n19680/Tube_example.scad), [Runsun's](http://forum.openscad.org/Bent-rod-td14003.html), [Johan's](http://forum.openscad.org/method-to-sweep-or-skin-a-hollow-object-without-difference-function-tp19677p19688.html) 65 | * [type-checking](http://forum.openscad.org/Determining-what-data-type-a-variable-is-holding-tp16111p16126.html) 66 | * [unit](http://forum.openscad.org/Output-inch-hardware-sizes-td19204.html) 67 | * [variable](http://forum.openscad.org/Ignoring-unknown-variable-issue-tp13156p13321.html)([2](http://forum.openscad.org/Special-Variables-tp14477p14512.html)) 68 | * [volume/center](http://forum.openscad.org/Volume-and-Center-of-mass-td15421.html) 69 | * [Warning, User](http://forum.openscad.org/Sweep-with-easing-equations-td20075.html) 70 | * Wavy solid: [Parkinbot's](http://forum.openscad.org/Sweeping-a-cone-through-a-range-of-angles-about-the-origin-tp19662p19676.html) 71 | 72 | ==> [Edit](https://github.com/runsun/OpenSCAD_Tips/edit/master/README.md) | [Menu](#menu) 73 | 74 | ### My_libs 75 | * [scadx](https://bitbucket.org/runsun/scadx) 76 | * [doctest](https://github.com/runsun/openscad_doctest) 77 | * [faces](http://forum.openscad.org/A-faces-function-for-simple-polyhedrons-td12809.html)([git](https://github.com/runsun/faces.scad)) 78 | * [offline doc](http://forum.openscad.org/Use-openscad-offliner-for-offline-documentation-td13096.html)([git](https://github.com/runsun/openscad_offliner)) 79 | * [runscad.py](http://forum.openscad.org/Animating-gif-with-3D-rotation-tp14011p14029.html)([2](http://forum.openscad.org/Symmetrical-Rotation-tp14062p14075.html), [git](https://gist.github.com/runsun/995250a8002386ab9abc)) 80 | * [synwrite](http://forum.openscad.org/Happy-New-Year-OpenSCAD-syntax-lexer-for-SynWrite-td15402.html)([2](http://www.thingiverse.com/thing:1237864)), [CudaText](http://forum.openscad.org/Syntax-highlighting-tp23247p23258.html) 81 | 82 | ==> [Edit](https://github.com/runsun/OpenSCAD_Tips/edit/master/README.md) | [Menu](#menu) 83 | 84 | ### Tools 85 | * [Daid's Polygon maker](http://daid.eu/~daid/3d/) 86 | * [Polygon Rabbit](http://www.protorabbit.nl/flash/polygonrabbit/PolygonRabbit.html) 87 | * [STL viewers](http://forum.openscad.org/looking-for-a-good-STL-viewer-locally-application-td19722.html)| 88 | * [Smithsonia X3D explorer](http://3d.si.edu/explorer?modelid=1341) 89 | * [SVGNesting](http://svgnest.com/) 90 | * [SketchPad](http://studio.sketchpad.cc/sp/account/sign-in?cont=http%3a%2f%2fstudio.sketchpad.cc%2f) 91 | * [GoJS polygon drawing](http://gojs.net/latest/extensions/PolygonDrawing.html?gclid=CNmkgNW0ldECFY22wAodAH8EZQ) 92 | * [osresearch papercraft](https://github.com/osresearch/papercraft) 93 | * [Neon22's Inkscape to OpenSCAD converter](http://www.thingiverse.com/thing:1065500) 94 | * [Desmos math calculator/plotter](https://www.desmos.com/calculator) 95 | * [Define/draw Bezier curve w/ desmos](https://www.desmos.com/calculator/cahqdxeshd) 96 | * jonathan.overholt's online cutlist tool: [legacy](https://jonathan.overholt.org/projects/cutlist), [new](http://cutlist.dotordotdot.com/current) 97 | 98 | ==> [Edit](https://github.com/runsun/OpenSCAD_Tips/edit/master/README.md) | [Menu](#menu) 99 | 100 | ### Libs 101 | * [Brendan M. Sleight's lasercut](https://github.com/bmsleight/lasercut) 102 | * [Hans Loeblich's functional](https://github.com/thehans/FunctionalOpenSCAD/blob/master/functional.scad) ([discussion](http://forum.openscad.org/Functional-OpenSCAD-working-with-vertex-data-td21080.html)) 103 | * [Carl Davidson's Relativity](https://github.com/davidson16807/relativity.scad/wiki) 104 | * [FunctionalOpenSCAD by thehans](https://github.com/thehans/functionalopenscad) 105 | 106 | ==> [Edit](https://github.com/runsun/OpenSCAD_Tips/edit/master/README.md) | [Menu](#menu) 107 | 108 | ### Lib_systems 109 | * [Revar Desmera's BOSL](https://github.com/revarbat/BOSL) 110 | * [Roya Sutton's odml](http://forum.openscad.org/Doxygen-openscad-amu-and-omdl-Documenting-and-Design-Flow-td19924.html) [pdf](https://cdn.thingiverse.com/assets/3c/16/d2/00/ea/refman.pdf) 111 | * [Jonathan Law's JointSCAD](https://github.com/HopefulLlama/JointSCAD) 112 | * [Justin Lin's dotSCAD](https://github.com/JustinSDK/dotSCAD) 113 | * [Revar Desmera's Belfry OpenScad Library](https://github.com/revarbat/BOSL) 114 | 115 | ==> [Edit](https://github.com/runsun/OpenSCAD_Tips/edit/master/README.md) | [Menu](#menu) 116 | 117 | ### OpenSCAD_variations 118 | * [openjscad.org](http://www.openjscad.org/) 119 | * [OpenJsCad](http://joostn.github.io/OpenJsCad/) 120 | * [ImplicitCad (ExtOpenScad)](http://www.implicitcad.org/examples/twisted_extrusion) 121 | * [OpenSCAD on rollApp](https://www.rollapp.com/launch/openscad) 122 | * [OpenSCAD on AWS](http://forum.openscad.org/Running-OpenSCAD-on-an-Amazon-AWS-EC2-server-td9544.html)([pdf](http://files.openscad.org/public/OpenSCAD%20on%20EC2.pdf)) 123 | * [OpenPyScad](https://github.com/taxpon/openpyscad) 124 | * [SolidPython](https://github.com/SolidCode/SolidPython) 125 | * [ScorchCad](http://www.scorchworks.com/ScorchCAD/scorchcad.html) - OpenSCAD clone for android 126 | 127 | ==> [Edit](https://github.com/runsun/OpenSCAD_Tips/edit/master/README.md) | [Menu](#menu) 128 | 129 | ### Other_cads 130 | * [3DSlash](https://www.3dslash.net/index.php) 131 | * [blockscad](https://blockscad.einsteinsworkshop.com/) 132 | * [freeCAD](https://www.freecadweb.org/) 133 | * [snapSCAD](https://github.com/martymcguire/snapscad) 134 | * [3DDoctors.net](http://3ddoctors.net/) 135 | * [libfive](https://libfive.com/studio/) 136 | * [Curv](https://github.com/doug-moen/curv) 137 | * [mattkeeter's Antimony](http://www.mattkeeter.com/projects/antimony/3/) (also look at [/1](http://www.mattkeeter.com/projects/antimony/1), [/2](http://www.mattkeeter.com/projects/antimony/2)) 138 | * [Scalptris](http://pixologic.com/sculptris/) 139 | * [ScatchUp](https://www.sketchup.com/) 140 | * [TinkerCAD](https://www.tinkercad.com/) 141 | * [Wings](http://www.wings3d.com/) 142 | * [Ultimaker Cura](https://ultimaker.com/en/products/ultimaker-cura-software) 143 | * [Top 5 CAD Software Available for Linux](https://itsfoss.com/cad-software-linux) 144 | 145 | ==> [Edit](https://github.com/runsun/OpenSCAD_Tips/edit/master/README.md) | [Menu](#menu) 146 | 147 | ### Other_Drawing_programs 148 | * [Context-free](https://github.com/MtnViewJohn/context-free) 149 | * [three.js](https://threejs.org/) 150 | * [Grasshopper (included in Rhino 6)](https://vimeopro.com/rhino/grasshopper-getting-started-by-david-rutten) 151 | * [Rhino 3d](https://www.rhino3d.com/gallery/12) 152 | 153 | ==> [Edit](https://github.com/runsun/OpenSCAD_Tips/edit/master/README.md) | [Menu](#menu) 154 | 155 | ### Other_portals 156 | * [shapeoko.com](http://www.shapeoko.com/wiki/index.php/OpenSCAD#Other_Support_Tools) 157 | * [Fablab](http://fablabamersfoort.nl/book/openscad) 158 | * [William Adams](http://www.shapeoko.com/wiki/index.php/Programmatic_G-Code_Generators) 159 | 160 | ==> [Edit](https://github.com/runsun/OpenSCAD_Tips/edit/master/README.md) | [Menu](#menu) 161 | 162 | ### Inspiration 163 | * [Santos's js 2d/3d transform lib](https://github.com/ruisoftware/jquery-rsSlideIt) 164 | * [Bending](https://en.wikipedia.org/wiki/Bending) 165 | 166 | ==> [Edit](https://github.com/runsun/OpenSCAD_Tips/edit/master/README.md) | [Menu](#menu) 167 | 168 | ### Subdivision 169 | 170 | * [Catmull-Clark Surface w/ code](http://hinjang.com/articles/04.html#eight) 171 | * [Tesselation w/ code](http://hinjang.com/articles/01.html#two) 172 | 173 | ==> [Edit](https://github.com/runsun/OpenSCAD_Tips/edit/master/README.md) | [Menu](#menu) 174 | 175 | ### References 176 | 177 | * [Triangulation by ear clipping](https://www.geometrictools.com/Documentation/TriangulationByEarClipping.pdf) 178 | * [A Primer on Bézier Curves](https://pomax.github.io/bezierinfo/), [B-splines](https://www.youtube.com/watch?v=qhQrRCJ-mVg), [Splines and Curves](http://graphics.stanford.edu/courses/cs148-09-fall/lectures/splines.pdf), [Hermite Curve Interpolation](http://www.cubic.org/docs/hermite.htm), [Curves and Splines](http://www.cs.cmu.edu/afs/cs/academic/class/15462-s10/www/lec-slides/lec06.pdf) 179 | * [The Cambridge Cluster Database](http://www-wales.ch.cam.ac.uk/~wales/CCD/Thomson/table.html): data pts of different spheres(Global Minima for the Thomson Problem) 180 | * Clipping: [Vatti Arbitrary Polygon Clipping Algorithm](http://what-when-how.com/computer-graphics-and-geometric-modeling/clipping-basic-computer-graphics-part-5/), [Martinez-Rueda](https://github.com/w8r/martinez) ([src](https://www.sciencedirect.com/science/article/pii/S0965997813000379)) 181 | * [Greiner-Hormann details](http://davis.wpi.edu/~matt/courses/clipping/) 182 | * Math: [R.Penner's Easing func](http://robertpenner.com/easing/) 183 | * Geometry: [2d collision detect in js](https://github.com/bmoren/p5.collide2D/blob/master/p5.collide2d.js) 184 | * Data structure: [Winged-edge](http://pages.mtu.edu/~shene/COURSES/cs3621/NOTES/model/winged-e.html) 185 | * UC Clavis Computer Graphics: [Sabastian Ng](https://www.youtube.com/watch?v=01YSK5gIEYQ) including subdivision, etc 186 | * Cutting-stock algorithm [wiki](https://en.wikipedia.org/wiki/Cutting_stock_problem), [jonathan.overholt](https://jonathan.overholt.org/projects/cutlist) 187 | * Triangulation: Shewchuk's Triangle [doc1](https://people.eecs.berkeley.edu/~jrs/papers/triangle.pdf),[doc2](http://www.cs.cmu.edu/~quake/triangle.delaunay.html), [code](http://www.cs.cmu.edu/~quake/triangle.html), [poly2tri lib](https://doc-snapshots.qt.io/qt5-5.9/qtlocation-attribution-poly2tri.html) 188 | * Decide the sideness of a pt on a line or a plane: [1](https://stackoverflow.com/questions/1560492/how-to-tell-whether-a-point-is-to-the-right-or-left-side-of-a-line/53823213#53823213) 189 | 190 | ==> [Edit](https://github.com/runsun/OpenSCAD_Tips/edit/master/README.md) | [Menu](#menu) 191 | -------------------------------------------------------------------------------- /snippets.md: -------------------------------------------------------------------------------- 1 | ## OpenSCAD snippets for copy and paste ## 2 | 3 | #### Menu 4 | | [**hash**(*h,k*)](#hash) | [**ichar**(*s,c*)](#ichar) | [**Line**(*pts*)](#line) | [**rotate-fixed**](#rotate_fixed) | [**rotate-any dir**](#rotate_anydir) | [**rotate-any axis**](#rotate_anyaxis) | 5 | |--|--|--|--|--|--| 6 | | [**sortArrs**(*arrs,by=0*)](#sortarrs) | [**spherePF**(*r,n*)](#sphere) | 7 | |--|--| 8 | 9 | --- 10 | ### hash 11 | | Type | API | Source | Remark | 12 | |------|-----|--------|--------| 13 | |Func| **hash**( *h,k* ) | Runsun | Very efficient search()-based associated array| 14 | 15 | ```c++ 16 | function hash(h,k, notfound)= 17 | ( 18 | let(rtn = h[ search([k], [for(i=[0:2:len(h)-2])h[i]])[0]*2+1 ]) 19 | rtn==undef?notfound:rtn 20 | ); 21 | 22 | echo( hash( ["a",1,"b",2], "a" ) ); // 1 23 | echo( hash( ["a",1,"b",2], "b" ) ); // 2 24 | echo( hash( ["a",1,"b",2], "c" ) ); // undef 25 | echo( hash( ["a",1,"b",2], "c", "missing" ) ); // "missing" 26 | ``` 27 | 28 | 29 | ```c++ 30 | // Associated functions: 31 | 32 | function keys(h)= [for(i=[0:2:len(h)-2]) h[i]]; 33 | function vals(h)= [for(i=[1:2:len(h)]) h[i]]; 34 | function haskey(h,k)= len([for( i=[0:2:len(h)-2]) if(h[i]==k)k ])>0; 35 | function kidx(h,k)= //= index of k in keys(h) 36 | [for(i=[0:2:len(h)-2]) if(h[i]==k)i/2][0]; 37 | function hashkvs(h)= [for(i=[0:2:len(h)-2]) [h[i],h[i+1]]]; 38 | >>> h = ["a",1, "b",2, 3,33]; 39 | >>> hashkvs(h); // [["a",1],["b",2],[3,33]] 40 | 41 | function delkey(h,k)= 42 | ( 43 | h?[ for(i=[0:len(h)-1]) 44 | if((i%2==0 && h[i]!=k)||(i%2!=0 && h[i-1]!=k)) h[i] 45 | ]:[] 46 | ); 47 | function delkeys(h,ks)= 48 | ( 49 | h?[ for(i=[0:len(h)-1]) 50 | if(i%2==0 && !has(ks,h[i])||(i%2!=0 && !has(ks,h[i-1]))) h[i] 51 | ]:[] 52 | ); 53 | 54 | function update(h,g)= 55 | ( 56 | !g? h //<=============== this line added 2015/3/17 57 | :!h? g //<=============== this line added 2015/6/10 58 | :[ for(i2=[0:len(h)+len(g)-1]) // Run thru entire range of h + g 59 | let(is_key= round(i2/2)==i2/2 // i2 is even= this position is a key 60 | ,is_h = i2=0 // Is cur k-v overlap btw h & g? 65 | ) 66 | if( !(overlap&&!is_h)) // Skip if overlap and current hash is g 67 | is_key? k 68 | : overlap?hash(g,k):cur_h[cur_i] 69 | ] 70 | ); 71 | ``` 72 | ==> [Menu](#menu) 73 | 74 | --- 75 | ### ichar 76 | 77 | | Type | API | Source | Remark | 78 | |------|-----|--------|--------| 79 | |Function| **ichar**( *s,c* ) | [Parkinbot](http://forum.openscad.org/taking-customizer-input-and-using-it-in-a-pair-of-nested-loops-tp23921p23935.html) | Return index of char (but not substr) in a str| 80 | 81 | ```c++ 82 | function ichar(s,c) = search(c, s, 0)[0][0]; 83 | ``` 84 | ==> [Menu](#menu) 85 | 86 | --- 87 | ### Line 88 | 89 | | Type | API | Source | Remark | 90 | |------|-----|--------|--------| 91 | |Module| **Line**( *pts* ) | Inspired by [Ronaldo](http://forum.openscad.org/Can-you-sweep-a-object-with-fingers-tp19057p19330.html) | Much more efficient than a direct hull() of points| 92 | 93 | ```c++ 94 | module Line( pts, r=0.05, closed=false, color=undef, transp=1, fn=4 ) 95 | { 96 | if(len(pts)>1 && len(pts[0])>1 && r>0) 97 | { 98 | // Convert to 3d if 2d; Attach 1st pt if closed 99 | pts = concat( [for(p=pts) [ p[0],p[1],p[2]==undef?0:p[2] ]], 100 | closed? [[ pts[0][0], pts[0][1], pts[0][2]==undef?0:pts[0][2] ]] : [] 101 | ); 102 | color(color,transp) 103 | for(i=[0:len(pts)-2]) 104 | { 105 | v = pts[i+1]-pts[i]; 106 | L = norm(v); 107 | if( L > 1e-12) 108 | translate(pts[i]) 109 | rotate([0, acos(v[2]/L), atan2(v[1],v[0])]) 110 | rotate(45) cylinder(h=L, r=r, $fn=fn); 111 | } 112 | } 113 | } 114 | ``` 115 | ==> [Menu](#menu) 116 | 117 | 118 | --- 119 | ### rotate_fixed 120 | 121 | | Type | API | Source | Remark | 122 | |------|-----|--------|--------| 123 | |Function| **rotate**( *angle* ) | [nophead](http://forum.openscad.org/Rounding-Errors-tp21821p21834.html) | Fix an issue of the built-in rotate()| 124 | 125 | ```c++ 126 | module rotate(angle) // built-in rotate is inaccurate for 90 degrees, etc 127 | { 128 | a = len(angle) == undef ? [0, 0, angle] : angle; 129 | cx = cos(a[0]); 130 | cy = cos(a[1]); 131 | cz = cos(a[2]); 132 | sx = sin(a[0]); 133 | sy = sin(a[1]); 134 | sz = sin(a[2]); 135 | multmatrix([ 136 | [ cy * cz, cz * sx * sy - cx * sz, cx * cz * sy + sx * sz, 0], 137 | [ cy * sz, cx * cz + sx * sy * sz,-cz * sx + cx * sy * sz, 0], 138 | [-sy, cy * sx, cx * cy, 0], 139 | [ 0, 0, 0, 1] 140 | ]) children(); 141 | } 142 | ``` 143 | ==> [Menu](#menu) 144 | 145 | 146 | --- 147 | ### rotate_anydir 148 | 149 | | Type | API | Source | Remark | 150 | |------|-----|--------|--------| 151 | |Function| **rotFromTo**( *vi,vo* ) | [Ronaldo](http://forum.openscad.org/rotate-45-45-0-tp24013p24015.html) | Rotate obj from one direction to another (no worry about angle) about an axis passing [0,0,0] | 152 | 153 | ```c++ 154 | module rotFromTo(vi,vo) 155 | if( norm(vi-vo)==0 || norm(vi)==0 || norm(vo)==0 ) 156 | children(); 157 | else 158 | mirror(vo/norm(vo)+vi/norm(vi)) mirror(vi) children(); 159 | ``` 160 | The functions to calc the corresponding rotation matrix: 161 | ```c++ 162 | function TrotFromTo(vi,vo) = 163 | norm(vi-vo)==0 || norm(vi)==0 || norm(vo)==0 ? 164 | [[1,0,0],[0,1,0],[0,0,1]] : 165 | Tmirror(vo/norm(vo)+vi/norm(vi)) * Tmirror(vi); 166 | 167 | function Tmirror(v) = 168 | norm(v)==0 ? 169 | [[1,0,0],[0,1,0],[0,0,1]] : 170 | let(u = v/norm(v)) 171 | [ [1,0,0] - 2*u[0]*u, [0,1,0] - 2*u[1]*u, [0,0,1] - 2*u[2]*u ]; 172 | ``` 173 | Usage example: [Placing obj on XY plane](http://forum.openscad.org/Rotation-question-tp24970p25000.html) 174 | 175 | ==> [Menu](#menu) 176 | 177 | 178 | --- 179 | 180 | ### rotate_anyaxis 181 | 182 | | Type | API | Source | Remark | 183 | |------|-----|--------|--------| 184 | |Function| **rotObj**(*pq,a*), **rotPts**(*pts,pq,a*) | Runsun | Rotate obj or points about ANY axis | 185 | ```c++ 186 | // Rotate an obj: rotObj( pq,a ) obj(); 187 | // Rotate points: rotPts( pts, pq, a ); 188 | function rotM(pq,a) = 189 | ( /* 190 | Rotation matrix about any arbitrary axis pq. 191 | http://www.fastgraph.com/makegames/3drotation/ 192 | */ 193 | let( /* if we move pq by moving p to ORIGIN, p=>q will be looking 194 | outward from the ORIGIN. This will result in wrong direction 195 | of rotation. So we need to reverse it. 196 | */ 197 | uv = ( pq[0]-pq[1])/norm(pq[1]- pq[0]) // unit vector 198 | , x=uv[0] 199 | , y=uv[1] 200 | , z=uv[2] 201 | , c=cos(a) 202 | , s=sin(a) 203 | , t=1-c 204 | ) 205 | [ [ t*(x*x)+c, t*(x*y)-s*z, t*(x*z)+s*y ] 206 | , [ t*(x*y)+s*z, t*(y*y)+c, t*(y*z)-s*x ] 207 | , [ t*(x*z)-s*y, t*(y*z)+s*x, t*(z*z)+c ] 208 | ] 209 | ); 210 | 211 | module rotObj( pq, a ) 212 | { 213 | translate( pq[1] ) 214 | multmatrix(m= rotM( pq,a) ) 215 | { 216 | translate( -1*pq[1] ) 217 | children(); 218 | } 219 | } 220 | function rotPt(pt,pq,a)= rotM(pq,a)*(pt-pq[0]) + pq[0] ; 221 | function rotPts(pts,pq,a)= [ for(p=pts) rotPt(p,pq,a) ] ; 222 | ``` 223 | ==> [Menu](#menu) 224 | 225 | 226 | --- 227 | ### sortArrs 228 | 229 | | Type | API | Source | Remark | 230 | |------|-----|--------|--------| 231 | |Function| **sortArrs**( *arrs,by=0* ) | [runsun](http://forum.openscad.org/Programming-in-Functional-OpenSCAD-tp23039p23280.html) | A quick sort for arrays based on given index. Inspired by [Ronaldo](http://forum.openscad.org/Programming-in-Functional-OpenSCAD-tp23039p23272.html) | 232 | 233 | ```c++ 234 | function sortArrs(arrs, by=0)= 235 | ( 236 | !(len(arrs)>0) ? [] : 237 | let( pivot = arrs[floor(len(arrs)/2)][by], 238 | lesser = [ for (y = arrs) if ( y[by] < pivot ) y ], , 239 | equal = [ for (y = arrs) if ( y[by] == pivot ) y ] , 240 | greater = [ for (y = arrs) if ( y[by] > pivot ) y ] 241 | ) 242 | concat( sortArrs(lesser, by), 243 | equal, 244 | sortArrs(greater, by) 245 | ) 246 | ); 247 | 248 | arrs = [[2.9, 1.9, -2.8], [-2.5, -1.5, -2.9], [-0.1, 2.8, 2.4], [0.9, 1.8, 249 | 0.8], [-1, -1.3, -0.8]] ; 250 | 251 | sortArrs(arrs,by=0): 252 | 253 | [[-2.5, -1.5, -2.9] 254 | , [-1, -1.3, -0.8] 255 | , [-0.1, 2.8, 2.4] 256 | , [0.9, 1.8, 0.8] 257 | , [2.9, 1.9, -2.8]] 258 | 259 | sortArrs(arrs,by=1): 260 | 261 | [[-2.5, -1.5, -2.9] 262 | , [-1, -1.3, -0.8] 263 | , [0.9, 1.8, 0.8] 264 | , [2.9, 1.9, -2.8] 265 | , [-0.1, 2.8, 2.4] 266 | ] 267 | 268 | sortArrs(arrs,by=2): 269 | 270 | [[-2.5, -1.5, -2.9] 271 | , [2.9, 1.9, -2.8] 272 | , [-1, -1.3, -0.8] 273 | , [0.9, 1.8, 0.8] 274 | , [-0.1, 2.8, 2.4]] 275 | 276 | ``` 277 | ==> [Menu](#menu) 278 | 279 | 280 | 281 | 282 | --- 283 | 284 | ### sphere 285 | 286 | | Type | API | Source | Remark | 287 | |------|-----|--------|--------| 288 | |Function| **spherePF**(*r,n*) | runsun | Modified from [berkenb's](http://forum.openscad.org/Coating-a-sphere-with-bumps-golf-ball-ish-for-wheel-treads-tp24090p24094.html) super efficient geodesic ssphere module | 289 | ```c++ 290 | function spherePF(r=1,n=1,_pts=[],_fcs=[])= 291 | ( 292 | // Modified from berkenb's excellent ssphere: 293 | // http://forum.openscad.org/Coating-a-sphere-with-bumps-golf-ball-ish-for-wheel-treads-tp24090p24094.html 294 | // return [pt, faces] 295 | 296 | _pts==[]? 297 | let( 298 | C0 = (1+sqrt(5))/4 299 | , pts = [ [0.5,0,C0],[0.5,0,-C0],[-0.5,0,C0],[-0.5,0,-C0] 300 | , [C0,0.5,0],[C0,-0.5,0],[-C0,0.5,0],[-C0,-0.5,0] 301 | , [0,C0,0.5],[0,C0,-0.5],[0,-C0,0.5],[0,-C0,-0.5]] 302 | , fcs = [ [10,2,0],[5,10,0],[4,5,0],[8,4,0],[2,8,0] 303 | , [11,1,3],[7,11,3],[6,7,3],[9,6,3],[1,9,3] 304 | , [7,6,2],[10,7,2],[11,7,10],[5,11,10],[1,11,5] 305 | , [4,1,5],[9,1,4],[8,9,4],[6,9,8],[2,6,8]] 306 | , npts = [for (v=pts) v/norm(v) ] 307 | ) 308 | ( n==0?[npts, fcs] 309 | : spherePF(r=r,n=n-1,_pts=npts,_fcs=fcs) 310 | ) 311 | : let( 312 | spts = concat(_pts 313 | , [ each for (f=_fcs) 314 | [(_pts[f[0]]+_pts[f[1]]) 315 | ,(_pts[f[1]]+_pts[f[2]]) 316 | ,(_pts[f[2]]+_pts[f[0]]) 317 | ] 318 | ] 319 | ) 320 | , nsfcs = [each for (i=[0:len(_fcs)-1]) 321 | [ [_fcs[i][0], len(_pts)+3*i+0, len(_pts)+3*i+2] 322 | , [len(_pts)+3*i+0, len(_pts)+3*i+1, len(_pts)+3*i+2] 323 | , [len(_pts)+3*i+0, _fcs[i][1], len(_pts)+3*i+1] 324 | , [len(_pts)+3*i+2, len(_pts)+3*i+1, _fcs[i][2]] 325 | ] 326 | ] 327 | , nspts = [for (v=spts) r*v/norm(v)] 328 | ) 329 | n==0? [nspts, nsfcs] 330 | : spherePF(r=r,n=n-1,_pts=nspts,_fcs=nsfcs) 331 | ); 332 | ``` 333 | ==> [Menu](#menu) 334 | 335 | 336 | 337 | 338 | --------------------------------------------------------------------------------