From 417caae2733dcbb86007bf74a8a3adcc136bdbcf Mon Sep 17 00:00:00 2001 From: Peter Ludikovsky Date: Thu, 6 Jun 2019 20:14:06 +0200 Subject: [PATCH] Initial commit --- .gitignore | 2 ++ LICENSE.txt | 11 +++++++++++ README.md | 33 +++++++++++++++++++++++++++++++++ scad-gen.rb | 43 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 89 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE.txt create mode 100644 README.md create mode 100755 scad-gen.rb diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f41aa29 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.scad +*.stl diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..146ff70 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,11 @@ +Copyright 2019 Peter Ludikovsky + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..cce2da0 --- /dev/null +++ b/README.md @@ -0,0 +1,33 @@ +scad-gen +======== + +Generate [OpenSCAD](https://openscad.org/) files for visualizations of +arbitrary functions. + +WHY?! +----- + +Why not? + +I wanted to be able to generate 3D models of various mathematical +functions after seeing [this +Tweet](https://twitter.com/nwilliams030/status/1112516582662721537) by +[\@nwilliams030](https://twitter.com/nwilliams030) + +How? +---- + +This is one simple Ruby script. At the top are the only things you need +to edit: + +- `t`: the starting input value for your function (*f*(0)) +- `step`: the stepping between function values +- `tmax`: the end value +- `calc(t)`: your function, expected to return an array with (x,y,z) + +The main loop iterates from `t` to `tmax` at `step` increments, +calculates the function `calc` at each step, and draws cylinders between +the points, with a sphere at each point (for a smoother appearance). + +After setting it all up, run the script, sending the output to a target +file. Open in OpenSCAD, render, voilĂ . diff --git a/scad-gen.rb b/scad-gen.rb new file mode 100755 index 0000000..96bb165 --- /dev/null +++ b/scad-gen.rb @@ -0,0 +1,43 @@ +#!/usr/bin/env ruby + +t = 0 +step = Math::PI / 10 +tmax = 2 * Math::PI + +def calc(t)[10 * Math.sin(t), 0, 10 * Math.cos(t)] +end + +old_vec = calc(0) + +iter = 0; + +puts <