neozhaoliang / pywonderland

A tour in the wonderland of math with python.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

A Tour in the Wonderland of Math with Python

A collection of python scripts for drawing beautiful figures and animating interesting algorithms in mathematics.

About this repo

The purpose of this project is to show the beauty of math with python by rendering high quality images, videos and animations. It consists of several independent projects with each one illustrates a special object/algorithm in math. The topics are chosen largely due to my personal taste:

  1. They must produce appealing results.
  2. There must be some non-trivial math behind them.
  3. The code should be as simple as possible.

What's fun here

  • Todd-Coxeter algorithm and uniform polytopes

    Use Todd-Coxeter algorithm to compute the data of a polytope, and render it in POV-Ray.

    [Book] | [Doc]

  • Möbius transformations

    • When a Möbius transformation is an isometry of the hyperbolic disk, it must be of elliptic/parabolic/hyperbolic type, and it's elliptic/parabolic/hyperbolic if and only if it's a composition of reflections about two intersecting/parallel/hyper-parallel mirrors.

    • A Möbius transformation can be uniquely extended to an isometry of the hyperbolic upper-half space.

  • Coxeter automata and 2D Uniform tilings

    [Casselman's Paper] | [Doc]

  • GIF animations of maze and cellular automata

    Generate maze animations containing thousands of frames in a few seconds. No external libs used and no drawing api call!

    [Doc]

  • Domino shuffling algorithm

    This algorithm samples a perfectly random tiling of a aztec diamond.

    [Mathologer Video] | [Paper]

  • Propp and Wilson's coupling from the past algorithm

    [Book]

  • Catacaustics of plane curves

    Use sympy to compute catacaustics of parametric and implicit curves.

    [Doc]

    Cardioid as a catacaustic of circle Nephroid as a catacaustic of cardioid
  • Coxeter element and Coxeter plane

    We explain how to project the E8 root system to its Coxeter plane.

    [Casselman's Paper] | [Doc]

    E8 5-Cube
  • Assassin vs Bodyguards

    Consider a room of regular polygon shape in the xy-plane, and let A (an "assassin") and T (a "target") be two arbitrary-but-fixed points within the room. Suppose that the room behaves like a billiard table, so that any ray (a.k.a "shot") from the assassin will bounce off the walls of the room, with the angle of incidence equaling the angle of reflection.

    Puzzle: Is it possible to block any possible shot from A to T by placing a finite number of points in the room?

    [PBS Video] | [math3ma blog]

How to use

All projects here are implemented in a ready-to-use manner for new comers. You can simply run the examples without tweaking any parameters once you have the dependencies installed correctly.

Dependencies

The recommended way to install all dependencies is simply running the bash script install_dependencies.sh.

sudo bash install_dependencies.sh

Or you can install the python libs by pip:

pip install -r requirements.txt

Open source softwares required:

  • python3-tk (for file dialog)
  • ImageMagick (for making gif animations)
  • FFmpeg (for saving animations to video files)
  • POV-Ray (for generating high quality raytracing results)
  • graphviz (for drawing automata of Coxeter groups)
  • Inkscape (optional, for convering large svg files to png)

They can all be installed via command-line:

sudo apt-get install python3-tk imagemagick ffmpeg povray graphviz inkscape

Note pygraphviz also requires libgraphviz-dev:

sudo apt-get install libgraphviz-dev

In the scripts these softwares are called in command line as povray, ffmpeg, convert (from ImageMagick), etc. For Windows users you should add the directories contain these .exe files to the system Path environment variables to let the system know what executables these commands refer to. For example on Windows the default location of POV-Ray's exe file is C:\Program Files\POV-Ray\v3.7\bin\pvengine64.exe, so you should add C:\Program Files\POV-Ray\v3.7\bin to system Path and rename pvengine64.exe to povray.exe, then you can run the scripts without any changes and everything should work fine.

Thanks

I have learned a lot from the following people:

License

see the LICENSE file.

About

A tour in the wonderland of math with python.

License:MIT License


Languages

Language:Python 60.1%Language:GLSL 31.8%Language:POV-Ray SDL 3.9%Language:Jupyter Notebook 2.1%Language:Asymptote 2.1%Language:Shell 0.0%