Schwimmbeckenknauf/Knauf.scad
2024-08-16 18:36:57 +02:00

98 lines
3.2 KiB
OpenSCAD

// Parameter
res=200; // Auflösung
du=50; // Durchmesser Kugel
a=32; // Rohrdurchmesser innen
b=38; // Rohrdurchmesser außen
//-------------------
$fn=res;
difference() {
// sphere(d=du);
ssphere(r=du/2, n=3);
difference() {
translate([0,0,-10 ])cylinder(h=50,d=b);
translate([0,0,-10.05])cylinder(h=50.05,d=a);
}
translate([-20,-20,15.5])cube([40,40,40]);
for(i= [0:36:259]) {
x = du * sin(i);
y = du * cos(i);
z = 0;
translate([x,y,z]) sphere (2);
}
}
function norm(v) = sqrt(v[0]*v[0]+v[1]*v[1]+v[2]*v[2]);
function normalize(v) = [v[0]/norm(v), v[1]/norm(v), v[2]/norm(v)];
function flatten(vec) = [for (v=vec) for(e=v) e];
module ssphere(r=1, n=0) {
C0 = (1+sqrt(5))/4;
pts = [[0.5, 0, C0], [0.5, 0, -C0], [-0.5, 0, C0], [-0.5, 0, -C0], [C0,
0.5, 0], [C0, -0.5, 0], [-C0, 0.5, 0], [-C0, -0.5, 0], [0, C0, 0.5], [0, C0,
-0.5], [0, -C0, 0.5], [0, -C0, -0.5]];
fcs = [[10, 2, 0], [5, 10, 0], [4, 5, 0], [8, 4, 0], [2, 8, 0], [11, 1, 3],
[7, 11, 3], [6, 7, 3], [9, 6, 3], [1, 9, 3], [7, 6, 2], [10, 7, 2], [11, 7,
10], [5, 11, 10], [1, 11, 5], [4, 1, 5], [9, 1, 4], [8, 9, 4], [6, 9, 8],
[2, 6, 8]];
npts = [for (v=pts) normalize(v)];
subdiv_sphere(npts, fcs, r, n);
}
module subdiv_sphere(pts, fcs, r, n) {
if (n>0) {
spts = concat(pts, flatten([for (f=fcs) [(pts[f[0]]+pts[f[1]]),
(pts[f[1]]+pts[f[2]]), (pts[f[2]]+pts[f[0]])]]));
nsfcs = flatten([for (i=[0:len(fcs)-1]) [[fcs[i][0], len(pts)+3*i+0,
len(pts)+3*i+2], [len(pts)+3*i+0, len(pts)+3*i+1, len(pts)+3*i+2],
[len(pts)+3*i+0, fcs[i][1], len(pts)+3*i+1], [len(pts)+3*i+2,
len(pts)+3*i+1, fcs[i][2]]]]);
nspts = [for (v=spts) r*normalize(v)];
subdiv_sphere(nspts, nsfcs, r, n-1);
}
else polyhedron(points=pts, faces=fcs);
}
// other
function spherePF(r=1,n=1,_pts=[],_fcs=[])=
(
// return [pt, faces]
_pts==[]?
let(
C0 = (1+sqrt(5))/4
, pts = [ [0.5,0,C0],[0.5,0,-C0],[-0.5,0,C0],[-0.5,0,-C0]
, [C0,0.5,0],[C0,-0.5,0],[-C0,0.5,0],[-C0,-0.5,0]
, [0,C0,0.5],[0,C0,-0.5],[0,-C0,0.5],[0,-C0,-0.5]]
, fcs = [ [10,2,0],[5,10,0],[4,5,0],[8,4,0],[2,8,0]
, [11,1,3],[7,11,3],[6,7,3],[9,6,3],[1,9,3]
, [7,6,2],[10,7,2],[11,7,10],[5,11,10],[1,11,5]
, [4,1,5],[9,1,4],[8,9,4],[6,9,8],[2,6,8]]
, npts = [for (v=pts) v/norm(v) ]
)
( n==0?[npts, fcs]
: spherePF(r=r,n=n-1,_pts=npts,_fcs=fcs)
)
: let(
spts = concat(_pts
, [ each for (f=_fcs)
[(_pts[f[0]]+_pts[f[1]])
,(_pts[f[1]]+_pts[f[2]])
,(_pts[f[2]]+_pts[f[0]])
]
]
)
, nsfcs = [each for (i=[0:len(_fcs)-1])
[ [_fcs[i][0], len(_pts)+3*i+0, len(_pts)+3*i+2]
, [len(_pts)+3*i+0, len(_pts)+3*i+1, len(_pts)+3*i+2]
, [len(_pts)+3*i+0, _fcs[i][1], len(_pts)+3*i+1]
, [len(_pts)+3*i+2, len(_pts)+3*i+1, _fcs[i][2]]
]
]
, nspts = [for (v=spts) r*v/norm(v)]
)
n==0? [nspts, nsfcs]
: spherePF(r=r,n=n-1,_pts=nspts,_fcs=nsfcs)
);