snake.mws

Spiralling String Curve

by Jakob Schmid 2004-08-14

Task:  We want to make a S-shaped parameter curve

First we make a simple circular curve:

>    plot([ cos(t), sin(t), t=0..2*Pi], axes=none);

[Maple Plot]

We can easily make it into a spiral:

>    plot([ cos(t)*t, sin(t)*t, t=0..2*Pi], axes=none);

[Maple Plot]

We can also translate the circular curve diagonally by adding t  to x  and y :

>    plot([ cos(t*3*Pi)+t, sin(t*3*Pi)+t, t=0..Pi], axes=none);

[Maple Plot]

We want to make the rotation change direction in the middle of the curve, so we use sin(t)  as the running variable instead of t:

>    plot([ cos(sin(t)*3*Pi)+t, sin(sin(t)*3*Pi)+t, t=0..Pi], axes=none);

[Maple Plot]

We make it spiral by multiplying with t:

>    plot([ cos(sin(t)*3*Pi)*t+t,
sin(sin(t)*3*Pi)*t+t, t=0..Pi], axes=none);

[Maple Plot]

The spiralling radius should be low at the beginning, high in the middle and low in the end. We do this by multiplying with sin(t)  instead of t (actually, 2sin(t) , but that's just an adjustment)

>    plot([
cos(sin(t)*6*Pi)*2*sin(t)+t,
sin(sin(t)*6*Pi)*2*sin(t)+t,
t=0..Pi], axes=none);

[Maple Plot]

If we parameterize the above formula, we get:

>    dc:=1:          # direction changes
sr:=6:          # spiralling rounds
r:=2:           # spiral relative radius
ss:=1:          # spiral radius change speed
tx:=1: ty:=1: # translation of x and y

C:=[cos(sin(t*dc)*sr*Pi)*r*sin(ss*t)+t*tx,
sin(sin(t*dc)*sr*Pi)*r*sin(ss*t)+t*ty, t=0..Pi];

C := [2*cos(6*sin(t)*Pi)*sin(t)+t, 2*sin(6*sin(t)*Pi)*sin(t)+t, t = 0 .. Pi]

Changing the parameters lead to many wonderous shapes:

>    dc:=1:          # direction changes
sr:=4:          # spiralling rounds
r:=2:           # spiral relative radius
ss:=3:          # spiral radius change speed
tx:=1: ty:=-1:  # translation of x and y
C:=[cos(sin(t*dc)*sr*Pi)*r*sin(ss*t)+t*tx,
sin(sin(t*dc)*sr*Pi)*r*sin(ss*t)+t*ty, t=0..Pi]:
plot(C, axes=none);

[Maple Plot]

>    dc:=1:         # direction changes
sr:=10:        # spiralling rounds
r:=0.9:        # spiral relative radius
ss:=11:        # spiral radius change speed
tx:=1: ty:=1:  # translation of x and y
C:=[cos(sin(t*dc)*sr*Pi)*r*sin(ss*t)+t*tx,
sin(sin(t*dc)*sr*Pi)*r*sin(ss*t)+t*ty, t=0..Pi]:
plot(C, axes=none);

[Maple Plot]

The snake shape is made with these parameters (also note the change in the interval t runs):

>    dc:=1:         # direction changes
sr:=2:         # spiralling rounds
r:=1.3:        # spiral relative radius
ss:=1.9:       # spiral radius change speed
tx:=.8: ty:=1: # translation of x and y
C:=[cos(sin(t*dc)*sr*Pi)*r*sin(ss*t)+t*tx,
sin(sin(t*dc)*sr*Pi)*r*sin(ss*t)+t*ty, t=.7..2.3]:
plot(C, axes=none, scaling=CONSTRAINED);

[Maple Plot]

We'll differentiate x(t)  and y(t)  to be able to calculate the tangent line to any point:

>    Dc:=1:         # direction changes
Sr:=2:         # spiralling rounds
R:=1.3:        # spiral relative radius
Ss:=1.9:       # spiral radius change speed
Tx:=.8: Ty:=1: # translation of x and y

f  := t -> Pi*Sr*sin(Dc*t):
x  := t -> cos(f(t))*R*sin(Ss*t)+t*Tx:
y  := t -> sin(f(t))*R*sin(Ss*t)+t*Ty:
The derivatives were done by hand (didn't seem like Maple was up to the task of differentiating x(t)  and y(t) ):
Dx := t -> R*(cos(f(t))*cos(Ss*t)*Ss
           - sin(f(t))*Pi*Sr*cos(Dc*t)*Dc*sin(Ss*t))+Tx:
Dy := t -> R*(sin(f(t))*cos(Ss*t)*Ss
           + cos(f(t))*Pi*Sr*cos(Dc*t)*Dc*sin(Ss*t))+Ty:
C:=[x(t), y(t), t=.7..2.3]:

The derivates look like this:

>    plot([Dx(t), Dy(t)], t=.7..2.3, axes=none);

[Maple Plot]