#! /usr/bin/gawk -f # Last edited on 1999-08-07 05:29:19 by hcgl BEGIN { pi = 3.14159265358979323; # Half-perimeter of unit-radius circle. ap = 0.28867513459481288; # Apothema of equilateral triangle, sqrt(3)/6 unit = 0.01; order = 7; radius = 250; printf "begin PZLR3Chain.T (format of 97-10-29)\n"; printf "unit = %.4f\n", unit; printf "samples = %d\n", 3 + 3*nsamples(order); xp = 0; yp = radius; xq = -0.5 * radius; yq = -ap * radius; xr = -xq; yr = yq; output(xp, yp, unit); koch(order, xp, yp, xq, yq, +1); output(xq, yq, unit); koch(order, xq, yq, xr, yr, +1); output(xr, yr, unit); koch(order, xr, yr, xp, yp, +1); printf "end PZLR3Chain.T\n"; } function koch(order, x1, y1, x2, y2, sgn, xu, yu, xh, yh) { # Draws an arc of Koch curve from (x1,y1) to (x2,y2) exclusive if (order == 0) { return; } else { xu = x2 - x1; yu = y2 - y1; xh = (x1+x2)/2 + sgn*ap*yu; yh = (y1+y2)/2 - sgn*ap*xu; koch(order-1, x1, y1, xh, yh, -sgn); output(xh, yh, unit); koch(order-1, xh, yh, x2, y2, -sgn); } } function nsamples(order) { # Number of samples generated by "koch(order, ...)" if (order == 0) { return (0); } else { return (1 + 2*nsamples(order-1)); } } function output(x, y, unit) { x = x + radius; y = y + radius; printf "%d %d 0 \n", int(x/unit + (x>0?+0.5:-0.5)), int(y/unit + (y>0?+0.5:-0.5)); }