(* Four-Knot (c) 1990 Stewart Dickson *)
cnum = 90;
tnum = 8;
radius = 2.5;

knot4 = {
	10 (Cos[t] + Cos[3 t]) + Cos[2 t] + Cos[4 t],
	6 Sin[t] + 10 Sin[3 t],
	4 Sin[3 t] Sin[5 t/2] + 4 Sin[4 t] - 2 Sin[6 t]
	};

SetOptions[Graphics3D, Boxed->False, RenderAll->False, AspectRatio->.47]

Unitize[a_] := N[a / Sqrt[a.a]]

VecLen[{x_, y_, z_}] := Sqrt[N[x ^2 + y ^2 + z ^2]];

Cross[A_List, B_List] :=
	Det[{
		{{1,0,0},	{0,1,0},	{0,0,1}},
		A,
		B
	}]

Angle[A_List, B_List] :=
	ArcCos[Unitize[A] . Unitize[B]]

tpoints = Table[N[knot4], {t, 0, 2Pi, 2Pi/cnum}];

tpoints[[-1]] = tpoints[[1]];

npoints = Table[Release[D[knot4, t]], {t, 0, 2Pi, 2Pi/cnum}]//N;


npoints = Map[Unitize, npoints];

npoints[[-1]] = npoints[[1]];

gvec = {0., 0., 1.};

vpoints = Map[
		(gvec -= (gvec . #) #)&,
		npoints
	];

vpoints = Map[Unitize, vpoints];

xpoints = Map[
		Apply[Cross, #]&,
		Transpose[{npoints, vpoints}]
	];

xpoints = Map[Unitize, xpoints];

error = Angle[vpoints[[1]], vpoints[[-1]]];

Do[
	{vpoints[[i]], xpoints[[i]]} =
		N[
			({{#1,#2},{-#2,#1}} . {vpoints[[i]], xpoints[[i]]})&
				[Cos[error(i-1)/cnum], Sin[error(i-1)/cnum]]
		],
	{i, 1, cnum+1}
];

vpoints[[-1]] = vpoints[[1]];
xpoints[[-1]] = xpoints[[1]];

scpoints = Table[N[{Cos[t], Sin[t]} radius],
		{t, 0, 2Pi, 2Pi/tnum}];

mesh = Table[
		tpoints[[i]] + scpoints[[j]] . {vpoints[[i]], xpoints[[i]]},
		{j, 1, tnum+1},
		{i, 1, cnum+1}
	];

shape = Table[
		Polygon[{
			mesh[[i, j]],
			mesh[[i+1, j]],
			mesh[[i+1, j+1]],
			mesh[[i, j+1]]
		}],
		{i, tnum},
		{j, cnum}
	]


Show[shape];


Print["done"]
