Skip to content

Instantly share code, notes, and snippets.

View GilesBathgate's full-sized avatar
😄

Giles Bathgate GilesBathgate

😄
View GitHub Profile
@GilesBathgate
GilesBathgate / gist:8229461
Created January 2, 2014 23:37
OpenSCAD hollow test case
//----TEST 1 ----------------
module test1() {
module hollow_cube() {
polyhedron([[-5,5,-5],[-5,-5,-5],[-5,-5,5],[-5,5,5],[5,-5,-5],[5,-5,5],[5,5,5],[5,5,-5],[-2.5,2.5,-2.5],[-2.5,-2.5,-2.5],[-2.5,-2.5,2.5],[-2.5,2.5,2.5],[2.5,-2.5,-2.5],[2.5,-2.5,2.5],[2.5,2.5,2.5],[2.5,2.5,-2.5]],[[0,1,2,3],[2,1,4,5],[3,2,5,6],[4,1,0,7],[7,0,3,6],[5,4,7,6],[8,9,10,11],[10,9,12,13],[11,10,13,14],[12,9,8,15],[15,8,11,14],[13,12,15,14]]);
}
difference(){
@GilesBathgate
GilesBathgate / gist:8235625
Created January 3, 2014 09:58
build_polyhedron_from_shell
template <class HDS>
class Build_polyhedron_from_shell : public CGAL::Modifier_base<HDS> {
struct Compare_handles{
template <class Handle>
bool operator()(Handle h1,Handle h2) const
{
return &(*h1) < &(*h2);
}
};
GRID_FINE=0.000001;
M_PI=3.14159265358979323846;
function getFragments(r,fn,fs,fa) =
(r < GRID_FINE)?3:
(fn > 0.0)?(fn >= 3 ? fn : 3):
ceil(max(min(360.0 / fa, r*2*M_PI / fs), 5));
function getPhi(i,f) = (i*360)/f;
function getCircle_x(r,i,f) = r*sin(getPhi(i,f));
@GilesBathgate
GilesBathgate / numbers.rcad
Created February 12, 2014 21:48
Simple numbers
module one() {
polyline([[0.25,1.2],[0.5,1.6],[0.5,0]]);
}
module two(){
//need to reverse order
polyline([[1.0,0],[0,0],[0,0.6],[0.25,0.8],[0.75,0.8],[1.0,1.0],[1.0,1.4],[0.75,1.6],[0.25,1.6],[0,1.4]]);
}
module three() {
@GilesBathgate
GilesBathgate / gear.scad
Last active August 29, 2015 13:56
Gear
function getR(r,i) = (i%4==i%2)?r:r-1;
function gear(r,l=[],i=0) = i>=360?l:gear(r,concat(l,[[getR(r,i)*sin(i),getR(r,i)*cos(i)]]),i+5);
function getRange(start,finish,v=[]) = len(v)>finish?v:getRange(start+1,finish,concat(v,start));
linear_extrude(height=2)
polygon(gear(r=6),[getRange(0,360/5)]);
polyhedron([[9,-9,-9],[-9,-9,-9],[-9,9,-9],[9,9,-9],[-9,-9,5.9083532657112947],[-9,-6.0136077412736828,7.6470346921629666],[-9,1.7902113064169236,8.7130653582999855],[-9,9,5.9083532657112965],[9,-9,5.9083532657112947],[9,9,5.9083532657112947],[9,6.0136077412736899,7.6470346921629631],[9,-1.7902113064169218,8.7130653582999855],[-6.0136077412736899,9,7.6470346921629648],[1.7902113064169236,9,8.7130653582999855],[-4.8516682795128094,7.2610347056602311,9],[-8.5649744193143924,1.703679338292039,9],[-7.2610347056602329,-4.8516682795128059,9],[-1.7036793382920421,-8.564974419314396,9],[4.8516682795128094,-7.2610347056602293,9],[8.5649744193143924,-1.7036793382920377,9],[7.2610347056602293,4.8516682795128094,9],[1.703679338292039,8.5649744193143924,9],[6.0136077412736899,-9,7.6470346921629631],[-1.7902113064169263,-9,8.7130653582999855]],[[0,1,2,3],[2,1,4,5,6,7],[8,0,3,9,10,11],[3,2,7,12,13,9],[14,15,16,17,18,19,20,21],[1,0,8,22,23,4],[14,12,7,6,15],[15,6,5,16],[17,16,5,4,23],[18,17,23,22],[8,11,19,18,22],[11,10,20,1
module a()
polyhedron([[-5,5,-5],[-5,-5,-5],[-5,-5,5],[-5,5,5],[5,-5,-5],[5,-5,5],[5,0,5],[0,0,5],[0,5,5],[5,5,-5],[0,5,0],[5,5,0],[5,0,0],[0,0,0]],[[0,1,2,3],[2,1,4,5],[3,2,5,6,7,8],[4,1,0,9],[9,0,3,8,10,11],[5,4,9,11,12,6],[6,12,13,7],[11,10,13,12],[8,7,13,10]]);
module b()
difference() {
cube(10,center=true);
cube(10);
}
difference() { a(); b(); }
/*************************************************
* Superformula
* (c) 2014 Torsten Paul <[email protected]>
* License: CC-BY-SA 3.0
*
* See http://en.wikipedia.org/wiki/Superformula
*/
// Display configuration
gridx = 50;
@GilesBathgate
GilesBathgate / glwrapper.cpp
Last active November 21, 2015 22:58
GLWrapper
#include "glwrapper.h"
GLWrapper* GLWrapper::instance=NULL;
extern "C" {
GLvoid Q_DECL_EXPORT glClear(GLbitfield mask)
{
GLWrapper::getInstance()->glClear(mask);
}
@GilesBathgate
GilesBathgate / issue802-cut-down.scad
Last active January 29, 2016 20:33
Minimal script that produces the target(s1).vertex()==target(s2).vertex() ERROR.
union() {
translate([ 83.7, 77, -35]) cube(5);
polyhedron( points = [
[153.898,59.513,-32.4658] , //0
[148.845,69.513,-31.6884] , //1
[148.845,74.513,-31.6884] , //2
[163.961,59.513,-33.9819] , //3
[162.25,59.513,-45.946] , //4
[147.116,74.513,-43.7824] , //5
[148.845,-74.513,-31.6884] , //6