Skip to content

Instantly share code, notes, and snippets.

@lorf
Last active June 22, 2017 15:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lorf/daa3a5095cc32c3d89b77d42d2316059 to your computer and use it in GitHub Desktop.
Save lorf/daa3a5095cc32c3d89b77d42d2316059 to your computer and use it in GitHub Desktop.
Crown in OpenSCAD
// http://3dtoday.ru/questions/vopros-po-modelirovaniyu/
$fn=256;
outer_radius=10;
inner_radius=7.5;
center_height=10;
half_tooth_height=5;
number_of_teeth=4;
// Vertical position of the top surface point depending on it's polar coordinates
function curve(rr,tt) = center_height+half_tooth_height*cos(tt*number_of_teeth)*(rr/outer_radius);
function points(tt) = [for (aa=[0:360/$fn:360-.001]) [
tt*sin(aa),
tt*cos(aa),
curve(tt,aa)
]];
function zero_z(points) = [for (ii=[0:len(points)-1]) [points[ii].x,points[ii].y,0]];
outerpoints=points(outer_radius);
innerpoints=points(inner_radius);
outertoppoints=outerpoints;
outerbottompoints=zero_z(outerpoints);
innertoppoints=innerpoints;
innerbottompoints=zero_z(innerpoints);
allpoints=concat(outerbottompoints,outertoppoints,innerbottompoints,innertoppoints);
outerfaces=[for (ii=[0:$fn-1]) [ii,(ii+1)%$fn,$fn+(ii+1)%$fn,$fn+ii]];
innerfaces=[for (ii=[0:$fn-1]) [2*$fn+ii,2*$fn+(ii+1)%$fn,3*$fn+(ii+1)%$fn,3*$fn+ii]];
bottomface=[concat([for (ii=[0:$fn]) 2*$fn+ii%$fn],[for (ii=[$fn:-1:0]) ii%$fn])];
topfaces1=[for (ii=[0:$fn-1]) [3*$fn+ii,$fn+ii,$fn+(ii+1)%$fn]];
topfaces2=[for (ii=[0:$fn-1]) [$fn+(ii+1)%$fn,3*$fn+(ii+1)%$fn,3*$fn+ii]];
allfaces=concat(outerfaces,innerfaces,bottomface,topfaces1,topfaces2);
polyhedron(points=allpoints,faces=allfaces);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment