
Screenshot of the program running in an Android cell phone
The functionality of the buttons is the same as in Chapter 7.
8.1 Creating the Function, Coordinates, and Mesh
Creating the Mesh and the Discrete Function
As mentioned, this code is analogous to the code described in Chapter 7.
8.2 Creating Two Images for the Stereoscopic Effect
Setting Parameters for the Stereoscopic View
As in previous chapters, the parameter D is the distance from the plane of projection to the screen. The VX1 and VX2 parameters represent the horizontal coordinates of the point of projection and are displaced between them. The rest of the coordinates are given by VY1=VY2 and VZ1=VZ2. The P parameter represents a percentage of the distance, D, at which the function is placed. For the stereoscopic view, we will set P=0.5 to place the function in the middle, between the plane of projection and the screen.
Code Initiating Variables When the Program Starts
We need a third image, which we will name PilImage3, to store the result of bitwise ORing the left and right images. The ShowScene(B) function creates this array.
8.3 Drawing the Plot
GraphFunction(VX, VY, VZ, Which) is in charge of drawing the plot. The Which parameter selects the image to be used; PilImage1 if 0 and PilImage2 if 1. Accordingly, Draw1 or Draw2 will be used.
Drawing on the screen is a time-consuming process. Therefore, to plot the function, it is convenient to calculate the whole set of points of a horizontal or vertical line trace. We will store this set in an array. This way, we can plot the corresponding line with only one access to the screen memory, instead of drawing segment by segment between points. This way, we diminish the processing time.
We create the array by utilizing the PointList=np.zeros( (N+1,2) directive and proceed to calculate a line trace, which consists of N+1, (x, y) points, ranging from the position 0 to N. The points in the array cannot be displayed directly on the screen. We first have to create a list in the appropriate format. This list is created by means of the List=tuple( map(tuple,PointList) ) directive. We proceed to draw the complete trace through the Draw.line( List, fill=(r,g,b), width=2) directive. The (r,g,b) parameters take the red or cyan color, according to the image selected, left or right, which is indicated by the Which parameter.
In the end, the function draws small text that reads 3D on the left corner of the scene.
Code for GraphFunction(VX,VY,VZ,Which)
The main.py Code
The file.kv Code
8.4 Surfaces with Saddle Points

Code for Plotting Equation (8.1)

Plot obtained with the program of Equation (8.1) showing a saddle point

8.5 Summary
In this chapter, we described elements for constructing stereoscopic 3D plots of analytical functions. We showed how to incorporate the coordinates and the mesh. Additionally, we described how to create the required PIL images that are ORed and convert the resulting image into a Kivy one to display it on the screen.