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"):
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"):
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):
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°):
Let us take another light and view.
>plot3d("sin(x)*sin(y)",r=pi,n=100,>hue,light=[-2,-2,0];height=-20°):
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°):
"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):
Contour lines and spectral colors can also be mixed.
>plot3d("x*y",>contour,>spectral):
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°):
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):
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°):
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):
Moreover, there is a bar plot, which may look good for real life data.
>plot3d(cumsum(random(10,10)),>bar,angle=-80°,height=20°):
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°):
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°):
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):
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):
You can also generate polar plots.
>plot3d("x*y",>polar):
Here is an implicit plot of the equation
>plot3d("x^2+y^2-z^2-1",r=3,zoom=2.5,implicit=5):
Here is another example.
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°):
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
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):
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):
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"):
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"):
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="."):
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):
Let us compute a specific level line containing the solutions of
First in 3D.
>plot3d("x^y-y^x",xmin=0,xmax=4,ymin=0,ymax=4,>hue,level=0, ... contourcolor=2):
Then in 2D.
>plot2d("x^y-y^x",a=0,b=8,c=0,d=8,>hue,level=0):