0
$\begingroup$

I am having trouble creating a Koch curve using the function KochCurve in Mathematica. What I want to create is something like this. enter image description here

However, what I end up with, using this code:

Graphics[KochCurve[2, {0, Pi/2, -Pi/2, -Pi/2, Pi/2}]]

is this enter image description here

As can be seen, the problem is that the triangles in the curve should be squares. How can I fix this problem?

$\endgroup$
7
$\begingroup$

As a workaround you can nest your path and call AnglePath:

n = 7;
angles = {0, π/2, -π/2, -π/2, π/2};

rots = {0, #} & /@ angles;
init = {1, #} & /@ angles;

iters = NestList[Function[s, Partition[Flatten[{#, s} & /@ rots], 2]], init, n - 1];

ListAnimate[Graphics[Line[AnglePath[#]]] & /@ iters]

enter image description here

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.