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?


1 Answer 1


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


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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