Skip to content

Instantly share code, notes, and snippets.

@stianeikeland
Last active April 14, 2019 10:11
Show Gist options
  • Save stianeikeland/0b5c5d065ce35c875594aa80feb78df9 to your computer and use it in GitHub Desktop.
Save stianeikeland/0b5c5d065ce35c875594aa80feb78df9 to your computer and use it in GitHub Desktop.
Oloid
(ns openscad-experiments.helpers
(:require [scad-clj.model :as m]
[scad-clj.scad :refer [write-scad]]))
(defn render [object]
(spit "render.scad" (write-scad object)))
(defn y-split [obj]
(let [box (m/cube 10 10 10)
holed-obj (m/difference obj (m/scale [1.005 1.2 1.005] box))
a (->> (m/cube 100 100 100)
(m/translate [0 -50 0])
(m/intersection holed-obj)
(m/rotate [(/ Math/PI -2) 0 0])
(m/translate [35 0 0]))
b (->> (m/cube 100 100 100)
(m/translate [0 50 0])
(m/intersection holed-obj)
(m/rotate [(/ Math/PI 2) 0 0])
(m/translate [-35 0 0]))]
(m/union a b (m/translate [0 -20 5] box))))
(defn oloid [radius]
(let [c (m/cylinder radius 0.1)
a (m/translate [0 (/ radius -2) 0] c)
b (->> c
(m/rotate [0 (/ Math/PI 2) 0])
(m/translate [0 (/ radius 2) 0]))]
(m/hull a b)))
(render (->> (oloid 30)
(m/with-fn 512)
(y-split)))
union () {
translate ([35, 0, 0]) {
rotate ([-90.0,0.0,0.0]) {
intersection () {
difference () {
hull () {
translate ([0, -15, 0]) {
cylinder ($fn=512, h=0.1, r=30, center=true);
}
translate ([0, 15, 0]) {
rotate ([0.0,90.0,0.0]) {
cylinder ($fn=512, h=0.1, r=30, center=true);
}
}
}
scale ([1.005, 1.2, 1.005]) {
cube ([10, 10, 10], center=true);
}
}
translate ([0, -50, 0]) {
cube ([100, 100, 100], center=true);
}
}
}
}
translate ([-35, 0, 0]) {
rotate ([90.0,0.0,0.0]) {
intersection () {
difference () {
hull () {
translate ([0, -15, 0]) {
cylinder ($fn=512, h=0.1, r=30, center=true);
}
translate ([0, 15, 0]) {
rotate ([0.0,90.0,0.0]) {
cylinder ($fn=512, h=0.1, r=30, center=true);
}
}
}
scale ([1.005, 1.2, 1.005]) {
cube ([10, 10, 10], center=true);
}
}
translate ([0, 50, 0]) {
cube ([100, 100, 100], center=true);
}
}
}
}
translate ([0, -20, 5]) {
cube ([10, 10, 10], center=true);
}
}
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment