
The program running on an Android cell phone showing plots of a hyperboloid at two different angles of rotation
The functionality of the buttons in the program is the same as in previous chapters.
In the following section, we describe the analytical approach.
16.1 Analytical Approach

Ellipse on a coordinate plane x-y

In Equation (16.1), as usual, the constant parameters a and b represent the length of the horizontal and vertical semi-axes, respectively.
Let’s consider a point with coordinates (xP, yP) on the plane x-y, at an arbitrary position on the ellipse and pointed by a vector rp, as depicted in Figure 16-2.

Rotation of the ellipse in Figure 16-2

Since the point (xP, yP) is a point of the ellipse, it satisfies Equation (16.1).

Equation (16.3) represents an ellipse of revolution.

Equation (16.4) is the equation of a three-dimensional ellipsoid.
In the following section, we describe our stereoscopic plotting approach of the ellipsoid.
16.2 Stereoscopic Ellipsoid Plotting


Spherical coordinate system used in this program




Equation (16.10) will be used to generate our plot.
Creating and Filling the r, Theta, and Phi Arrays
In this code, Theta entries range from 0 to π, and Phi ranges from 0 to 2π. Both arrays have N+1 entries. The radial distance is represented by the two-dimensional array (N+1) x (N+1), r, and stores the values given by Equation (16.10).
Creating Mesh Arrays
The two nested for loops are used to fill the mesh according to Equations (16.6)-(16.8).

Stereoscopic scene of an ellipsoid with a=100, b=90, and c=60, plotted with the code
Code for the main.py (Ellipsoid) File
Code for the file.kv File
16.3 Hyperboloid
As in the case of the ellipsoid, we will first consider the equation of a hyperbola on the x-y plane.

Vertical hyperbola on the plane x-y





The argument within the square root in Equation (16.15) can be zero or negative for some values. Therefore, the radial distance can result in an undefined or a complex number. This characteristic is a natural consequence of the hyperboloid shape, as it consists of two separated surfaces. Therefore, to avoid plotting at these values, we will proceed as follows.
We will vary the angle ϕ between 0 and 2π. However, the values that θ can take must be split into two intervals, one for plotting the upper surface and the other for the bottom surface. The first interval is between 0 and some value θ0< θMax and the second one is between π and π + θ0. Here, θMax is the maximum allowed value that θ can take to avoid undefined or complex values in Equation (16.15). It is possible to exactly calculate θMax; however, for illustrative purposes, it will be sufficient to propose and test some values.
Filling Two Independent Arrays for the Hyperboloid
In this code, θ0, represented in the code by Theta0, was set to 40 degrees. We set this value arbitrarily as a first trial. The multiplying factor π/180 converts entries from degrees to radians. For simplicity, we tested different values for θ0, taking care of attaining only real values for the radial distance as given by Equation (16.15). The ThetaA, ThetaB, and Phi arrays all have sizes N+1.
Creating Two Mesh Sets
Creating Two Arrays for the Radial Distances
Filling the Two Mesh Values
In this code listing, L is a scaling factor that allows us to change the dimensions of the plot.
The GraphFunction (VX,VY,VZ,Which) and RotateFunction (B, Sense) functions are similar to the ones described in previous chapters. There is a slight difference, however. Instead of using one array for plotting only one surface, these functions use two arrays for plotting the upper and bottom surfaces.
main.py (for the Hyperboloid)
16.4 Summary
In this chapter, we introduced elements for plotting stereoscopic three-dimensional conics. We presented an analytical approach to constructing them. We also utilized working examples to illustrate the programming process.