Knots

Written by Paul Bourke
October 1992


The following describes a few parametric functions in 3 dimensions which give the appearance of knots in a piece of string.

Knot 1

Knot 2

This is a special case of the more general torus knot described in knot 3.

Knot 3

This is an example of a torus knot which exists on the surface a torus. It is characterised by the number of time it wraps around the meridian and longitudinal axis of a torus.

Knot 4

There are a whole family of curves including knots which are formed by the equations:

x = r * cos(phi) * cos(theta)
y = r * cos(phi) * sin(theta)
z = r * sin(phi)

which are the equations for converting from polar to Cartesian coordinates except that we make r, theta, phi a function of a parameter beta which ranges from 0 to pi.

For the following

r(beta) = 0.8 + 1.6 * sin(6 * beta)
theta(beta) = 2 * beta
phi(beta) = 0.6 * pi * sin(12 * beta)

Knot 5

Using the same systems of equations as in knot 4, with

r(beta) = 1.2 * 0.6 * sin(0.5 * pi + 6 * beta)
theta(beta) = 4 * beta
phi(beta) = 0.2 * pi * sin(6 * beta)

C Source for Knot 1

#include "stdio.h"
#include "stdlib.h"
#include "math.h"

#define TWOPI 6.283185307179586476925287
#define NSEGMENTS 1000
#define RADIUS .50

int main(argc,argv)
int argc;
char **argv;
{
   int i;
   double x,y,z,xlast,ylast,zlast;
   double mu;

   for (i=0;i<=NSEGMENTS;i++) {
      mu = i * TWOPI / (double)NSEGMENTS;
      x = 10 * (cos(mu) + cos(3*mu)) + cos(2*mu) + cos(4*mu);
      y = 6 * sin(mu) + 10 * sin(3*mu);
      z = 4 * sin(3*mu) * sin(5*mu/2) + 4*sin(4*mu) - 2 * sin(6*mu);

      /*
         Write the geometry in any format you like
         Here I create sphere and cylinder combinations for Radiance
      */
      if (i < NSEGMENTS)
         printf("surf sphere s%d\n0 0 4 %g %g %g %g\n",i,x,y,z,RADIUS);
      if (i != 0)
         printf("surf cylinder c%d\n 0 0 7 %g %g %g %g %g %g %g\n",
            i,xlast,ylast,zlast,x,y,z,RADIUS);
      xlast = x;
      ylast = y;
      zlast = z;
   }
}

C Source for Knot 2

#include "stdio.h"
#include "stdlib.h"
#include "math.h"

#define PI 3.141592653589793238462643
#define TWOPI 6.283185307179586476925287
#define NSEGMENTS 1000
#define RADIUS 0.1

int main(argc,argv)
int argc;
char **argv;
{
   int i;
   double x,y,z,xlast,ylast,zlast;
   double mu;

   for (i=0;i<=NSEGMENTS;i++) {
      mu = i * TWOPI / (double)NSEGMENTS;
      x = (4 * cos(mu + PI)) / 3 + 2 * cos(3 * mu);
      y = 4 * sin(mu) / 3 + 2 * sin(3 * mu);
      z = sin(4 * mu) + sin(2 * mu) / 2;

      if (i < NSEGMENTS)
         printf("surf sphere s%d\n0 0 4 %g %g %g %g\n",i,x,y,z,RADIUS);
      if (i != 0)
         printf("surf cylinder c%d\n 0 0 7 %g %g %g %g %g %g %g\n",
            i,xlast,ylast,zlast,x,y,z,RADIUS);
      xlast = x;
      ylast = y;
      zlast = z;
   }
}

C Source for Knot 3

#include "stdio.h"
#include "stdlib.h"
#include "math.h"

#define TWOPI 6.283185307179586476925287
#define NSEGMENTS 1000
#define RADIUS 0.05

int main(argc,argv)
int argc;
char **argv;
{
   int i;
   double x,y,z,xlast,ylast,zlast;
   double mu;
   int nlongitude,nmeridian;

   nmeridian  = atoi(argv[1]);
   nlongitude = atoi(argv[2]);

   for (i=0;i<=NSEGMENTS;i++) {
      mu = i * TWOPI * nmeridian / (double)NSEGMENTS;
      x = cos(mu) * (1 + cos(nlongitude*mu/(double)nmeridian) / 2.0);
      y = sin(mu) * (1 + cos(nlongitude*mu/(double)nmeridian) / 2.0);
      z = sin(nlongitude*mu/(double)nmeridian) / 2.0;

      if (i < NSEGMENTS)
         printf("surf sphere s%d\n0 0 4 %g %g %g %g\n",i,x,y,z,RADIUS);
      if (i != 0)
         printf("surf cylinder c%d\n 0 0 7 %g %g %g %g %g %g %g\n",
            i,xlast,ylast,zlast,x,y,z,RADIUS);
      xlast = x;
      ylast = y;
      zlast = z;
   }
}




Eight Knot

By Paul Bourke
January 2001

x = 10 (cos(t) + cos(3 t)) + cos(2 t) + cos(4 t)
y = 6 sin(t) + 10 sin(3 t)
z = 4 sin(3 t) sin(5 t / 2) + 4 sin(4 t) - 2 sin(6 t)
0 < t < 2 pi

Knot in Second Life




Cinquefoil Knot

Graphics by Paul Bourke
November 2004

x = cos(u) [ 2 - cos(2 u/(2 k + 1)) ]
y = sin(u) [ 2 - cos(2 u/(2 k + 1)) ]
z = -sin(2 u/(2 k + 1))
where 0 < u < (4 k + 2) pi

k=1, see Trefoil Knot.

k=2

k=3




Trefoil Knot

Graphics by Paul Bourke
November 2004

x = 41 cos(u) - 18 sin(u) - 83 cos(2 u) - 83 sin(2 u) - 11 cos(3 u) + 27 sin(3 u)
y = 36 cos(u) + 27 sin(u) - 113 cos(2 u) + 30 sin(2 u) + 11 cos(3 u) - 27 sin(3 u)
z = 45 sin(u) - 30 cos(2 u) + 113 sin(2 u) - 11 cos(3 u) + 27 sin(3 u)
where 0 < u < 2 pi




Granny Knot

Graphics by Paul Bourke
November 2004

x = -22 cos(u) - 128 sin(u) - 44 cos(3 u) - 78 sin(3 u)
y = -10 cos(2 u) - 27 sin(2 u) + 38 cos(4 u) + 46 sin(4 u)
z = 70 cos(3 u) - 40 sin(3 u)
where 0 < u < 2 pi

PovRay source




Second Life




3D printed