3D Parametric Curves are cool because they
make it easy to construct beautiful shapes out of simple mathematical formulas.
Since I am lazy and not good at modeling 3D scenes, I thought that using these
equations was probably the best way to get nice images.
The following curves are made of cylinders, following the paths defined by the parametric curves.
void trefoilKnot(float R, float t, float4& p)
{
p.x = R*(sin(t)+2.f*sin(2.f*t));
p.y = R*(cos(t)-2.f*cos(2.f*t));
p.z = R*(-sin(3.f*t));
}
void torus(float R, float t, float4& p )
{
p.x = R*(3.f*cos(t)+cos(10.f*t)*cos(t));
p.y = R*(3.f*sin(t)+cos(10.f*t)*sin(t));
p.z = R*sin(10.f*t);
}
void star(float R, float t, float4& p )
{
p.x = R*(2.f*sin(3.f*t)*cos(t));
p.y = R*(2.f*sin(3.f*t)*sin(t));
p.z = R*sin(3.f*t);
}
void spring(float R, float t, float4& p)
{
p.x = R*cos(t);
p.y = R*sin(t);
p.z = R*cos(t);
}
void heart(float R, float u, float v, float4& p)
{
p.x = R*4.f*pow(sin(u),3.f);
p.y = R*0.25f*(13*cos(u)-5*cos(2.f*u)-2.f*cos(3.f*u)-cos(4.f*u));
p.z = 0.f;
}
void thing(float R, float t, float4 a, float4& p)
{
p.x = R*(sin(t)+a.x*sin(a.y*t));
p.y = R*(cos(t)-a.x*cos(a.y*t));
p.z = R*(-sin(a.z*t));
}
void moebius(float R, float u, float v, float s, float du, float dv, float4& p )
{
p.x = 2.f*R*(cos(u)+v*cos(u/2)*cos(u));
p.y = 2.f*R*(sin(u)+v*cos(u/2)*sin(u));
p.z = 2.f*R*(v*sin(u/2));
}