iconEuler Home

3D Plots

This is a demo of the 3d plotting features of Euler. Euler knows many
different types of three dimensional plots. We can only demonstrate
some of them here.

Note that currently Euler uses an own rendering algorithm for 3D
plots, which produces nice and relatively fast plots. If you need more
advanced scenes, you can use the Povray engine.

We use the all in one function "plot3d" here. Here is a first example.
Euler plots an expression in x and y. As always, press the TAB key to
bring the plot window to the front.
>plot3d("x*y^3",title="x*y^3"):

03 - Introduction to 3D Graphics

You can add user interaction with user=true.

Turn the plot around with the function keys. + and - will zoom in and
out. The space key resets the view. End the interaction with the
return key.
>plot3d("abs(x)+abs(y)",>user,zlabel="|x|+|y|",title="Cursor keys or return"):

03 - Introduction to 3D Graphics

You can also change the bounds of the plot range.
>plot3d("sin(x)*sin(y)",a=0,b=2*pi,c=0,d=2*pi):

03 - Introduction to 3D Graphics

The next plot uses a finer grid and adds shading. The light source is
overhead, but this can be changed too. With height=70°, we select a
view more from the top.
>plot3d("sin(x)*sin(y)",r=pi,n=100,>hue,height=70°):

03 - Introduction to 3D Graphics

Let us take another light and view.
>plot3d("sin(x)*sin(y)",r=pi,n=100,>hue,light=[-2,-2,0];height=-20°):

03 - Introduction to 3D Graphics

This is the default view of many graphics programs. The spectral
colors mark the height of the function.
>plot3d("x^2+y^3",>spectral,angle=30°):

03 - Introduction to 3D Graphics

"plot2d" can also add level lines.
>plot3d("sin(x)*sin(y)",r=pi,n=100, ...
   light=[1,0,0],level=-1:0.25:1,>hue):

03 - Introduction to 3D Graphics

Contour lines and spectral colors can also be mixed.
>plot3d("x*y",>contour,>spectral):

03 - Introduction to 3D Graphics

Or we can show just the level lines, and no surface. Let us zoom in a
little closer.
>plot3d("x^2+y^3",r=2,contour=2,zoom=2.5,angle=40°):

03 - Introduction to 3D Graphics

The next plot rotates the function x^2+1 around the x-axis.
>plot3d("x^2+1",rotate=1,xmin=-2,xmax=2,n=50,>hue):

03 - Introduction to 3D Graphics

The following is a simple wireplot. This type of plot may be the
best choice for complicated functions.
>plot3d("x^y-y^x",a=0,b=2,c=0,d=2,>wire,angle=180°):

03 - Introduction to 3D Graphics

The sliced plot sliced through the graph of the plot.
>plot3d("x^2+y^2",a=0,b=1,c=0,d=1,>sliced,angle=0,n=10):

03 - Introduction to 3D Graphics

Moreover, there is a bar plot, which may look good for real life
data.
>plot3d(cumsum(random(10,10)),>bar,angle=-80°,height=20°):

03 - Introduction to 3D Graphics

Euler can even create a 3D view of the plot using an anaglyph image.
You need red/cyan glasses to view this properly.
>plot3d("x^2+y^3",>anaglyph,angle=-40°):

03 - Introduction to 3D Graphics

Euler scales all functions to fit into a cube window. However, you
can also get an undistorted view of the function graph.
>plot3d("x^2+y^3",>hue,level="auto",<fscale,angle=30°):

03 - Introduction to 3D Graphics

Parameterized Surfaces

It is also possible to use arithmetic expressions for each
coordinates of a 3D surface.

Here is parametrization of the unit ball with light from the upper
right.
>plot3d("cos(x)*cos(y)","sin(x)*cos(y)","sin(y)", ...
   xmin=0,xmax=2*pi,ymin=-pi/2,ymax=pi/2,>hue, ...
   light=[1,0,1],<frame,zoom=4):

03 - Introduction to 3D Graphics

The following commands generate a paraboloid. The Euler matrix
language helps a lot here. 

Moreover, we compute a matrix of values W, containing the distance
from a point on the surface to (1/2,1/2,1/4). This matrix can be used
to define the contour lines.
>x=-1:0.05:1; y=x'; z=x*y; ...
 W=sqrt((x-0.5)^2+(y-0.5)^2+(z-0.25)^2); ...
 plot3d(x,y,z,level=0:0.2:2,values=W,scale=[1,1,0.8], ...
   angle=-100°,height=40°,hues=W/2.3,color=-2):

03 - Introduction to 3D Graphics

You can also generate polar plots.
>plot3d("x*y",>polar):

03 - Introduction to 3D Graphics

Implicit Plots

Here is an implicit plot of the equation

03 - Introduction to 3D Graphics


>plot3d("x^2+y^2-z^2-1",r=3,zoom=2.5,implicit=5):

03 - Introduction to 3D Graphics

Here is another example. 

03 - Introduction to 3D Graphics

By specifying the direction in the implicit parameter, we can plot
cuts along each axis.
>plot3d("x^2*y-y^3-z^2",>implicit,r=2,angle=70°,height=30°):

03 - Introduction to 3D Graphics

The Moebius Strip

Next, we want to generate the Moebius strip.

First we need parameters, one going once round the circle, and the
other from -1 to 1.
>x=linspace(0,2*pi,100); y=(-1:0.1:1)';
Because one of them is a column vector, the other a row vector, an
expression like y*sin(x) generates a matrix of values y[i]*sin(x[j]).
So we get three matrices of x-, y-, and z-values of our surface.

Thus we generate the coordinates

03 - Introduction to 3D Graphics

of the Moebius strip.
>plot3d(cos(x)*(1+y/2*cos(x/2)),sin(x)*(1+y/2*cos(x/2)),y/2*sin(x/2), ...
  scale=1.5,<frame):

03 - Introduction to 3D Graphics

Let us add shading. hue=2 means that the shading does not depend on
surface orientation.
>plot3d(cos(x)*(1+y/2*cos(x/2)),sin(x)*(1+y/2*cos(x/2)),y/2*sin(x/2), ...
   frame=0,hue=2,max=0.8,scale=1.5):

03 - Introduction to 3D Graphics

Curves and Point Clouds

The easiest way to plot a curve in 3D uses three equations.
>plot3d("cos(x)","sin(x)","x",xmin=0,xmax=10,>lines,>user, ...
   scale=1.5,frame=2,title="Press return or cursor keys"):

03 - Introduction to 3D Graphics

But it is also possible to enter three vectors of points for
each coordinate.

In the following example, we generate a normal random walk,
and display the path in 3D.
>A=cumsum(normal(3,1000));  ...
   plot3d(A[1],A[2],A[3],>wire,>user,scale=1.2,zoom=2.5, ...
   title="Try pressing a for anaglyph view"):

03 - Introduction to 3D Graphics

Now let us draw a normal distributed cloud of 10000 points in
3D.
>A=normal(3,1000); plot3d(A[1],A[2],A[3], ...
   >points,zoom=2.5,style="."):

03 - Introduction to 3D Graphics

Implicit Plots

It is also possible to generate a plot of level lines of a function
together with hues for the valus of the function in 2D using plot2d.
>plot2d("x^2+y^3",>contour,>hue,>spectral):

03 - Introduction to 3D Graphics

Let us compute a specific level line containing the solutions of

03 - Introduction to 3D Graphics

First in 3D.
>plot3d("x^y-y^x",xmin=0,xmax=4,ymin=0,ymax=4,>hue,level=0, ...
   contourcolor=2):

03 - Introduction to 3D Graphics

Then in 2D.
>plot2d("x^y-y^x",a=0,b=8,c=0,d=8,>hue,level=0):

03 - Introduction to 3D Graphics

Euler Home