June 4th, 2010 | 3 Comments
If one have a coordinate system with n-dimension, then one of the dimensions can be expressed by the n-1 other dimensions, e.g. z = f(x,y).
But if you want to plot functions that are defined in polar coordinates, e.g. a sphere, they are complicated to define with z = f(x,y). But Gnuplot offers you a way to handle this type of functions by using its parametric mode. In parametric mode the functions are expressed in angular coordinates t or u,v dependend on the dimensions of your plot.
In the 2D case we have only one free dimension:
y = f(x) => x = fx(t), y = fy(t)
In Fig. 1 we see the connections between the angular coordinate
t and radius
x,y that is given by
x = r cos(t) y = r cos(π/2-t) = r sin(t)
Using the result from above it is very easy to plot a circle:
set parametric set trange [0:2*pi] # Parametric functions for a circle fx(t) = r*cos(t) fy(t) = r*sin(t) plot fx(t),fy(t)
In three dimensions we have the case:
z = f(x,y) => x = fx(u,v), y = fy(u,v), z = fz(u,v)
In Fig. 3 we see the connection between the two angular variables
u (that is
t in the 2D case),
v and the radius
x = r cos(v) cos(u) y = r cos(v) sin(u) z = r sin(u)
Using the parametric variables
u,v it is very easy to draw a sphere or a piece of a sphere:
set parametric set urange [0:3.0/2*pi] set vrange [-pi/2:pi/2] # Parametric functions for the sphere fx(v,u) = r*cos(v)*cos(u) fy(v,u) = r*cos(v)*sin(u) fz(v) = r*sin(v) splot fx(v,u),fy(v,u),fz(v)
The result is shown in Fig. 4. Note that we have to use 3.0/2, because 3/2 is 1 for Gnuplot!