Koch curve is a kind of plane curve: From a segment of the middle One-third of the section with equilateral two edge, the formation of the graph has four edges, five nodes. Then make the same processing for each line segment of the edge in turn.
Iterations as shown:
A little change, painted into hexagonal, raised direction to both sides, with random color, painted after the snowflake-shaped.
Program code:
private void Layoutroot_loaded (object sender, RoutedEventArgs ea)
{
Double sqrt3 = math.sqrt (3);
Point A = new Point ((float) (+ sqrt3));
Point B = new Point ((float) (+ + * sqrt3));
Point C = new Point (float) (+ + * sqrt3));
Point d = new Point (Sqrt3, (float) (+ +));
Point e = new Point (200, 100);
Point f = new Point (100, 100);
Line (A, B, 5);
Line (b, a, 5);
Line (b, C, 5);
Line (c, B, 5);
Line (c, D, 5);
Line (d, C, 5);
Line (d, E, 5);
Line (E, D, 5);
Line (E, F, 5);
Line (f, E, 5);
Line (F, a, 5);
Line (A, F, 5);
}
private void Line (point A, point B, int n)
{
if (n > 0)
{
Double r = Math.atan (Math.Abs (A.Y-B.Y)/Math.Abs (a.x-b.x)); Angle
Double v = 0;
Point C = new Point (a.x + (b.x-a.x)/3, A.Y + (B.Y-A.Y)/3);
Point d = new Point (a.x + 2 * (b.x-a.x)/3, A.Y + 2 * (B.Y-A.Y)/3);
Double L = math.sqrt ((c.x-d.x) * (c.x-d.x) + (C.Y-D.Y) * (C.Y-D.Y));
Point e;
if (b.y-a.y >= 0 && b.x-a.x > 0)
{
v = r;
}
else if (b.y-a.y > 0 && b.x-a.x <= 0)
{
v = math.pi-r;
}
else if (b.y-a.y <= 0 && b.x-a.x < 0)
{
v = Math.PI + R;
}
else if (B.y-a.y < 0 && b.x-a.x >= 0)
{
v = 2 * math.pi-r;
}
E = new Point ((float) (L * Math.Cos (v + math.pi/3) + c.x), (float) (c.y + L * Math.sin (v + math.pi/3)));
Line (A, C, n-1);
Line (c, E, n-1);
Line (E, D, n-1);
Line (d, b, n-1);
}
Else
{
Line L = new Line ();
Random rnd = new Random ();
Color C = Color.FromArgb (255, (byte) rnd. Next (255), (byte) rnd. Next (255), (byte) rnd. Next ());
L.stroke = new SolidColorBrush (c);
l.x1 = a.x;
L.y1 = A.Y;
l.x2 = b.x;
L.y2 = B.Y;
LAYOUTROOT.CHILDREN.ADD (l);
}
}
Run the results as shown in figure:
Each part of the Koch curve consists of 4 small curves with the same shape as its own ratio of 1:3, then its Hausdorff dimension number (fractal dimension) is D=log (4)/log (3) =1.26185950714 ...