# This example illustrates how to use gnuplot for plotting parametric curves.
# We plot the images under the Cayley map z \mapsto (z-i)/(z+i) of lines parallel to 
# the real and imaginary axis, respectively.
#
# Author: Konstantin Poelke, 04/2013
#

# Switch to parametric mode, then we can plot curves parametrized by t
set parametric

# Set sample density to smoothen plots
set samples 500

# Define some line styles
# Line type (lt) is solid line
# Line width (lw) should be 3 
set style line 1 lt 1 lw 3  linecolor rgb "red"
set style line 2 lt 1 lw 3  linecolor rgb "blue"
set style line 3 lt 1 lw 3  linecolor rgb "green"

# Set scaling of x and y axis of the plot.
set xrange[-2:2]
set yrange[-2:2]

# Real and imaginary part with the x variable being the parameter t
# The constant y values are parametrized by some constant c
rx(t,c)=(t**2+c**2-1)/(t**2+(c+1)**2)  
ix(t,c)=-2*t/(t**2+(c+1)**2)

# Set first terminal as output
set term wxt 0

# Add a title to the plot
set title "Lines parallel to the real axis transformed by the Cayley map"

# Plot three parametric curves, for different constant values for y=c
plot [-50:50] rx(t,1), ix(t,1) ls 1, rx(t,10), ix(t,10) ls 2, rx(t,-2), ix(t,-2) ls 3


# Real and imaginary part, this time with the y variable being the parameter t
# The constant x values are parametrized by some constant c
ry(c,t)=(c**2+t**2-1)/(c**2+(t+1)**2)  
iy(c,t)=-2*c/(c**2+(t+1)**2)

# Open a second terminal window
set term wxt 1

# Add a title to the plot
set title "Lines parallel to the imaginary axis transformed by the Cayley map"

# Plot three parametric curves, for different constant values for x=c
plot [-50:50] ry(1,t), iy(1,t) ls 1, ry(10,t), iy(10,t) ls 2, ry(-2,t), iy(-2,t) ls 3