Koch Star
Pattern based on Koch curve
T-Spine visualization of Koch curve structure
1
def k1 (p:var[]..[])
2
{
3
v1 = Vector.ByTwoPoints(p[0],p[1]).Normalized();
4
d1 = p[0].DistanceTo(p[1]);
5
p1 = p[0].Translate(v1,d1/3);
6
v2 = v1.Rotate(Vector.ZAxis(),60);
7
p2 = p1.Translate(v2,d1/3);
8
p3 = p1.Translate(v1,d1/3);
9
return [p[0],p1,p2,p3,p[1]];
10
};
Copied!
With Loops
1
2
def k2 (pts:var[]..[])
3
{
4
p1 = List.DropItems(List.Sublists(pts,0..1,1),-1);
5
p2 = k1(p1<1>);
6
p3 = Point.PruneDuplicates(List.Flatten(p2,-1),0.1);
7
return List.AddItemToEnd(p3[0],p3);
8
};
9
10
def k3 (pt:var[]..[],it:int)
11
{
12
a = [Imperative]
13
{
14
c = 0;
15
b = [];
16
while (c < it)
17
{
18
b = k2(pt);
19
pt = b;
20
c = c + 1;
21
}
22
return b;
23
}
24
return a;
25
};
Copied!
With Recursion
1
2
def k2(pts:var[]..[],n:int[]..[])
3
{
4
a = [Imperative]
5
{
6
if (List.Count(pts)>=Math.Pow(5,n))
7
return pts;
8
else
9
{
10
b = [Associative]
11
{
12
p1 = List.DropItems(List.Sublists(pts,0..1,1),-1);
13
p2 = k1(p1<1>);
14
p3 = List.Flatten(p2,-1);
15
return p3;
16
}
17
return Point.PruneDuplicates(k2(b,n),0.1);
18
}
19
}
20
b = List.Clean(List.Flatten(a,-1),false);
21
return List.AddItemToEnd(List.FirstItem(b),b);
22
};
Copied!
Visualization with T-Splines
1
// T Spline Visualization
2
p001 = List.Transpose(Circle.ByCenterPointRadius(Point.Origin(),
3
[50,35,25,5])<1>.PointAtParameter((1..0..#4)<2>));
4
p002 = k2(p001<1>,2).Translate(Vector.ZAxis(),[0,10,15,60]);
5
pc01 = PolyCurve.ByPoints(List.Transpose(p002));
6
pc02 = PolyCurve.ByPoints(pc01.PointAtParameter((0..1..#10)<1>));
7
ts01 = TSplineSurface.BuildPipes(List.Flatten(pc01.Explode(),-1),
8
1.5,0.1,3,true,false,0,0,1,0.3,1,1,true);
9
ts02 = TSplineSurface.BuildPipes(pc02.Explode(),2..0.2..#10,
10
2..0.2..#10,3,true,false,0,0,1,0.3,1,1,true);
11
ts03 = TSplineSurface.ByCombinedTSplineSurfaces
12
(List.Flatten([ts01,ts02],-1)).Translate(150,0,0);
Copied!
koch.stl
98MB
Binary
STL file
Last modified 2mo ago
Copy link