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


This is a special case of the more general torus knot described in 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.



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)

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

#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;
}
}
#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;
}
}
#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;
}
}