# Koch Star

![T-Spine visualization of Koch curve structure](/files/-Ml8OvtgRWDXhwMFx-1N)

```
def k1 (p:var[]..[])
{
	v1 = Vector.ByTwoPoints(p[0],p[1]).Normalized();
	d1 = p[0].DistanceTo(p[1]);
	p1 = p[0].Translate(v1,d1/3);
	v2 = v1.Rotate(Vector.ZAxis(),60);
	p2 = p1.Translate(v2,d1/3);
	p3 = p1.Translate(v1,d1/3);
	return [p[0],p1,p2,p3,p[1]];
};
```

![](/files/-MlA9LDroo3GpXvf3Ahq)

With Loops

```

def k2 (pts:var[]..[])
{
	p1 = List.DropItems(List.Sublists(pts,0..1,1),-1);
	p2 = k1(p1<1>);
	p3 = Point.PruneDuplicates(List.Flatten(p2,-1),0.1);
	return List.AddItemToEnd(p3[0],p3);
};

def k3 (pt:var[]..[],it:int)
{
	a = [Imperative]
	{
		c = 0;
		b = [];
		while (c < it)
		{
			b = k2(pt);
			pt = b;
			c = c + 1;
		}
		return b;
	}
	return a;
};
```

![](/files/-MlA9QuB3m0dnPiwNZVA)

With Recursion

```

def k2(pts:var[]..[],n:int[]..[])
{
	a = [Imperative]
	{
		if (List.Count(pts)>=Math.Pow(5,n))
			return pts;
		else
		{
			b = [Associative]
			{
				p1 = List.DropItems(List.Sublists(pts,0..1,1),-1);
				p2 = k1(p1<1>);
				p3 = List.Flatten(p2,-1);
				return p3;
			}
			return Point.PruneDuplicates(k2(b,n),0.1);
		}
	}
	b = List.Clean(List.Flatten(a,-1),false);
	return List.AddItemToEnd(List.FirstItem(b),b);
};
```

![](/files/-MlA9dNoDk0amjQ3LurK)

Visualization with T-Splines

```
// T Spline Visualization
p001 = List.Transpose(Circle.ByCenterPointRadius(Point.Origin(),
[50,35,25,5])<1>.PointAtParameter((1..0..#4)<2>));
p002 = k2(p001<1>,2).Translate(Vector.ZAxis(),[0,10,15,60]);
pc01 = PolyCurve.ByPoints(List.Transpose(p002));
pc02 = PolyCurve.ByPoints(pc01.PointAtParameter((0..1..#10)<1>));
ts01 = TSplineSurface.BuildPipes(List.Flatten(pc01.Explode(),-1),
1.5,0.1,3,true,false,0,0,1,0.3,1,1,true);
ts02 = TSplineSurface.BuildPipes(pc02.Explode(),2..0.2..#10,
2..0.2..#10,3,true,false,0,0,1,0.3,1,1,true);
ts03 = TSplineSurface.ByCombinedTSplineSurfaces
(List.Flatten([ts01,ts02],-1)).Translate(150,0,0);
```

{% file src="/files/5oseCdF6qavIFO2yvrdb" %}
STL file
{% endfile %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://gitbook.testingwaters.in/patterns/koch-star.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
