This notebook illustrates some plotting capabilities of manifold objects in SageMath.
More examples can be found on the SageManifolds page.
%display latex
Let us consider the sphere $\mathbb{S}^2$. In SageMath, we declare it as a 2-dimensional differentiable manifold:
S2 = Manifold(2, 'S^2', latex_name=r'\mathbb{S}^2', start_index=1)
print(S2)
We then introduce the standard spherical coordinates $(\theta,\phi)$ as a chart on $\mathbb{S}^2$, denoting the chart as spher
and the coordinates th
and ph
.
We shall be lazy here and consider that the spherical chart covers the whole manifold $\mathbb{S}^2$; this amounts to authorize coordinate singularities:
spher.<th,ph> = S2.chart(r'th:[0,pi]:\theta ph:[0,2*pi]:periodic:\phi')
spher
spher.coord_range()
For 3D plots, we shall require the Euclidian space $\mathbb{E}^3$:
E3.<X,Y,Z> = EuclideanSpace()
E3
Let us call cartesian
the chart of Cartesian coordinates $(X,Y,Z)$:
cartesian = E3.cartesian_coordinates()
cartesian
The canonical embedding of $\mathbb{S}^2$ into $\mathbb{E}^3$:
Phi = S2.diff_map(E3, (sin(th)*cos(ph),
sin(th)*sin(ph),
cos(th)),
name='Phi', latex_name=r'\Phi')
Phi.display()
Each chart is endowed with a plot()
method.
For instance, we may use it to plot the chart of spherical coordinates plotted in terms
of itself:
spher.plot(chart=spher)
More intersting is to the plot the chart of spherical coordinates in terms of $\mathbb{E}^3$'s Cartesian coordinates, via the embedding $\Phi:\; \mathbb{S}^2\to\mathbb{E}^3$:
spher.plot(chart=cartesian, mapping=Phi)
For a better image, let us increase the number of coordinate values:
spher.plot(chart=cartesian, mapping=Phi, number_values=11)
One can customize the color of coordinate lines:
spher.plot(chart=cartesian, mapping=Phi, number_values=11,
color={th: 'red', ph: 'green'})
One can fix the value of some coordinates, thereby obtaining a partial plot:
spher.plot(chart=cartesian, mapping=Phi, number_values=11,
color={th: 'red', ph: 'green'},
fixed_coords={th: pi/4})
or limit the range of some coordinates:
spher.plot(chart=cartesian, mapping=Phi, number_values=11,
color={th: 'red', ph: 'green'},
ranges={ph:(0, pi)})
One can also restrict the coordinates of the ambiant chart; here is a example of plot of the chart spher
in terms of the coordinates $(X,Y)$ of $\mathbb{E}^3$:
spher.plot(chart=cartesian, mapping=Phi, number_values=11,
color={th: 'red', ph: 'green'},
ambient_coords=(X, Y))
Same thing with only the coordinates $(X,Z)$:
spher.plot(chart=cartesian, mapping=Phi, number_values=11,
color={th: 'red', ph: 'green'},
ambient_coords=(X, Z))
Let us introduce the chart of stereographic coordinates from the North pole:
stereoN.<x,y> = S2.chart()
stereoN
spher_to_stereoN = spher.transition_map(stereoN,
(sin(th)*cos(ph)/(1-cos(th)),
sin(th)*sin(ph)/(1-cos(th))))
spher_to_stereoN.display()
spher_to_stereoN.set_inverse(2*atan(1/sqrt(x^2+y^2)), atan2(-y,-x)+pi)
Plot of spherical coordinate in terms of the stereographic ones:
spher.plot(chart=stereoN, number_values=15, ranges={th: (pi/8,pi)},
color={th: 'red', ph: 'green'})
Plot of stereographic coordinates in terms of spherical ones:
stereoN.plot(chart=spher, number_values=15, plot_points=200,
color={x: 'blue', y: 'orange'})
The expression of the embedding $\Phi$ in terms of the stereographic coordinates is computed by Sage:
Phi.display()
This means that we can use $\Phi$ for a 3D view of the stereographic chart:
stereoN.plot(chart=cartesian, mapping=Phi, number_values=25,
color={x: 'blue', y: 'orange'})
The hole at the North pole is due to the default limitation to $[-8,8]$ for the plot range of coordinates that span the whole real line. We can change it to $[-20, 20]$ via the argument max_range
:
stereoN.plot(chart=cartesian, mapping=Phi, number_values=25,
color={x: 'blue', y: 'orange'},
max_range=20, plot_points=200)