Draw Poincare's disk in Python

I wondered if it was on the net, but I didn't find it, so I'll write it myself.

What is Poincare's disk?

It is famous for Escher's thing.

Since the explanation will be long, the one implemented in Python and the source code are as follows.

image.png

import numpy as np
import matplotlib.pyplot as plt

theta = np.linspace(0,2*np.pi,100)
colorlist = ["r","g","b","c","m","y"]

t = list(range(0,6))
for n in t:
    n2 = np.power(2,n)
    for phi in np.linspace(0,2*np.pi,2*n2+1):
        x = np.cos(theta)*np.tan(np.pi/n2) + np.cos(phi)/np.cos(np.pi/n2)
        y = np.sin(theta)*np.tan(np.pi/n2) + np.sin(phi)/np.cos(np.pi/n2)
        plt.plot(x,y,lw=0.5,color=colorlist[n-2])

for phi in np.linspace(0,2*np.pi,9):
    t = np.linspace(-2,2,100)
    x = t*np.cos(phi)
    y = t*np.sin(phi)
    plt.plot(x,y,lw=0.5,color='y')

plt.plot(np.cos(theta),np.sin(theta),color='black')
plt.xlim(-1,1)
plt.ylim(-1,1)
plt.show()

It is said that this is an infinitely expanding hyperbolic space confined in one disk, but this alone is not enough to explain, and it is the miso that confined the "hyperbolic space" instead of the "flat space". I think it is.

Hyperbolic space

Hyperbolic space is a space where a straight line looks like a hyperbola. In the first place, just because the space you see in front of you is straight does not mean that it will continue straight forever. Even the earth is round. Since all the straight lines on the surface of the earth are perfect circles (correctly, spheroids) when viewed on a planetary scale, it can be said that the earth is a space where all straight lines are circles. On the contrary, there should be a space where all straight lines are hyperbolas. The table is as follows.

Type of space Sum of angles of a triangle Non-parallel straight lines Parallel straight lines*
Spherical > 180 degrees Intersect at 2 points Do not intersect
Plane =180 degrees Intersect at one point Do not intersect
Hyperboloid <180 degrees Intersect at one point or not intersect Do not intersect

Considering a space in which the grid on the Euclidean plane (lattice coordinates) is a hyperbola, the following conditions are satisfied. Transcription to Euclidean coordinates is as follows.

image.png

You can see that the rectangle towards the edge is clearly sharp. This still reflects the angle correctly, but it's hard to see the whole picture, so let's say you compress it ** by force ** on a disk. Let's set infinity $ = 1 $ as appropriate.

Euclidean plane $ U $ → Vertical projection on hyperboloid $ H $ → Center projection to origin

This compression can be done rather naturally by the procedure. The calculation formula can also be calculated with a simple similarity. Let the converted coordinate system be $ D $.

U:[x_U,y_U] \longmapsto H:[x_H,y_H,z_H]\\
x_H = x_U\\
y_H = y_U\\
z_H = \sqrt{x_U^{2}+y_U^{2}+1}\\
H:[x_H,y_H,z_H] \longmapsto D:[x_D,y_D,1]\\
x_D = \frac{x_H}{z_H}\\
y_D = \frac{y_H}{z_H}\\

The result is:

image.png

Easy to see! Such a model is called ** Klein's disk **. This connects the asymptote of the hyperbola and the intersection of infinity with a straight line, and although the positional relationship in a Euclidean sense is easy to understand, it has the disadvantage that it does not accurately reflect the angle of each straight line (originally 90). The intersections below the degree also look at right angles).

Therefore, this time, we will perform the operation of compressing into a disk while maintaining the angle between the straight lines. The result is what is called a ** Poincare disk **, and the operation is as follows.

D:[x_D,y_D,1] \longmapsto P:[x_P,y_P,0]\\
x_P = \frac{x_D}{1+\sqrt{1-x_D^{2}-y_D^{2}}}\\
y_P = \frac{y_D}{1+\sqrt{1-x_D^{2}-y_D^{2}}}\\

The result is: image.png

You can see that the intersection of each straight line and point at infinity (circumference) is a right angle, and that the angle between the straight lines is kept the same as that of Euclidean coordinates.

Application to other than grid

Until now, for the explanation of hyperbolic space, the grid (hyperbolic curves arranged like) was converted as it is, but I will also convert other things. Consider the following set of hyperbolas.

image.png

Suddenly it became psychedelic, but please calm down because all the lines are hyperbolas.

Converting this to Klein's disk,

image.png

When converted to Poincare's disk,

image.png

It will be like this. In this way, the first figure was drawn.

Note that in all these figures, the topological relationships such as the number of sides and the positional relationship ** of the figure surrounded by each straight line have not changed.

Supplement

In the source code at the beginning, the Poincare disk is realized by drawing a circle without going through the above complicated calculations. Of course, by applying the above transformation to the hyperbola, it will eventually become a circle, and you can create a Poincare disk.

Recommended Posts

Draw Poincare's disk in Python
Draw graph in python
Draw mp3 waveform in Python
Draw "Draw Ferns Programmatically" in Python
Draw implicit function in python
Draw a heart in Python
Draw Sine Waves in Blender Python
Draw knots interactively in Plotly (Python)
Draw a CNN diagram in Python
Quadtree in Python --2
Python in optimization
CURL in python
Metaprogramming in Python
Python 3.3 in Anaconda
SendKeys in Python
Draw Nozomi Sasaki in Excel with python
Epoch in Python
Discord in Python
Draw a heart in Python Part 2 (SymPy)
Sudoku in Python
DCI in Python
quicksort in python
nCr in python
N-Gram in Python
Programming in python
Plink in Python
Constant in python
Lifegame in Python.
FizzBuzz in Python
Sqlite in python
StepAIC in Python
Draw a tree in Python 3 using graphviz
N-gram in python
LINE-Bot [0] in Python
Csv in python
Disassemble in Python
Reflection in Python
Constant in python
nCr in Python.
format in python
Scons in Python3
Puyo Puyo in python
python in virtualenv
PPAP in Python
Quad-tree in Python
Reflection in Python
Chemistry in Python
Hashable in python
DirectLiNGAM in Python
LiNGAM in Python
Flatten in python
flatten in python
Draw a graph of a quadratic function in Python
Draw contour lines that appear in textbooks (Python)
Draw graphs in Julia ... Leave the graphs to Python
[Python] How to draw a histogram in Matplotlib
Sorted list in Python
Daily AtCoder # 36 in Python
Clustering text in Python
Daily AtCoder # 2 in Python
Implement Enigma in python