From ebed3f44c3d9b436d4b9ee9e95c761bbb140ff47 Mon Sep 17 00:00:00 2001 From: neozhaoliang Date: Sat, 3 Feb 2024 15:12:13 +0800 Subject: [PATCH] fix hopf fibration pov file missing bug --- README.md | 2 +- src/cftp/README.md | 2 +- src/misc/Hopf_Fibration.ipynb | 4 +-- src/misc/hopf_fibration.pov | 52 +++++++++++++++++++++++++++++++++++ src/misc/lorenz.py | 8 ++---- src/misc/modulargroup.py | 22 ++++++++------- 6 files changed, 70 insertions(+), 20 deletions(-) create mode 100644 src/misc/hopf_fibration.pov mode change 100755 => 100644 src/misc/modulargroup.py diff --git a/README.md b/README.md index 7668587..0eb3b7b 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ # A Tour in the Wonderland of Math with Python -[![CI](https://github.com/neozhaoliang/pywonderland/actions/workflows/test.yaml/badge.svg)](https://github.com/neozhaoliang/pywonderland/actions/workflows/test.yaml) \ No newline at end of file +[![CI](https://github.com/neozhaoliang/pywonderland/actions/workflows/test.yaml/badge.svg)](https://github.com/neozhaoliang/pywonderland/actions/workflows/test.yaml) diff --git a/src/cftp/README.md b/src/cftp/README.md index 89ec04c..88923fe 100644 --- a/src/cftp/README.md +++ b/src/cftp/README.md @@ -3,5 +3,5 @@ 1. [Blog post](https://possiblywrong.wordpress.com/2018/02/23/coupling-from-the-past/) by Possibly Wrong. 2. Wilson's paper "Mixing times of lozenge tiling and card shuffling Markv chains". 3. Häggström's book "Markov chains and algorithmic applications" -4. Book by David Asher Levin, Elizabeth Lee Wilmer, and Yuval Peres "Markov chains and mixing times". +4. "Markov chains and mixing times". Book by David Asher Levin, Elizabeth Lee Wilmer, and Yuval Peres. 5. [Markov Chain Algorithms for Planar Lattice Structures](https://www.researchgate.net/publication/2455641_Markov_Chain_Algorithms_for_Planar_Lattice_Structures). \ No newline at end of file diff --git a/src/misc/Hopf_Fibration.ipynb b/src/misc/Hopf_Fibration.ipynb index beda259..e5d0536 100644 --- a/src/misc/Hopf_Fibration.ipynb +++ b/src/misc/Hopf_Fibration.ipynb @@ -42,7 +42,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "To visualize the Hopf fibration we want to choose some points on the 2-sphere $S^2$, draw their fibers and and see what they look like. Since these fibers lie in the 4d space we cannot see them directly, but if we project them to 3d space using the [stereographic projection](https://en.wikipedia.org/wiki/Stereographic_projection) then some remarkable structure appears. The fibers are projected to circles in 3d space (one of which in a line, comes from the fiber through infinity), any two such circles are linked with each other and the line passes through all circles. The 3d space is filled with nested tori made of linking Villarceau circles, each tori is the preimage of a circle of latitude of the 2-sphere. \n", + "To visualize the Hopf fibration, we will choose some points on the 2-sphere $S^2$, draw their fibers and and see what they look like. Since these fibers lie in the 4d space we cannot see them directly, but if we project them to 3d space using the [stereographic projection](https://en.wikipedia.org/wiki/Stereographic_projection) then some remarkable structure appears. The fibers are projected to circles in 3d space (one of which in a line, comes from the fiber through infinity), any two such circles are linked with each other and the line passes through all circles. The 3d space is filled with nested tori made of linking Villarceau circles, each tori is the preimage of a circle of latitude of the 2-sphere. \n", "\n", "So our plan is:\n", "\n", @@ -360,7 +360,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.10" + "version": "3.10.12" }, "latex_envs": { "LaTeX_envs_menu_present": true, diff --git a/src/misc/hopf_fibration.pov b/src/misc/hopf_fibration.pov new file mode 100644 index 0000000..ac3d636 --- /dev/null +++ b/src/misc/hopf_fibration.pov @@ -0,0 +1,52 @@ +#version 3.7; + +global_settings { + assumed_gamma 2.2 + max_trace_level 10 +} + +#declare TubeThickness = 0.05; + +#macro Torus(center, rad, mat, col) + torus { + rad, TubeThickness + texture { + pigment { + color col + } + finish { + ambient 0.4 + diffuse 0.5 + specular 0.6 + roughness 0.1 + reflection 0 + } + } + matrix + translate center + } +#end + +union { + #include "torus-data.inc" +} + +camera { + location <0, 0, 1> * 9 + look_at <0, 0, 0> + right x*image_width/image_height + up y + sky y +} + +light_source { + <0, 1, 1> * 100 + color rgb 1 + area_light + x*32, z*32, 5, 5 + adaptive 1 + jitter +} diff --git a/src/misc/lorenz.py b/src/misc/lorenz.py index b5455e3..083b5db 100644 --- a/src/misc/lorenz.py +++ b/src/misc/lorenz.py @@ -30,11 +30,7 @@ def derivative(point, t): fig = plt.figure(figsize=(6.4, 4.8), dpi=100) ax = fig.add_axes( - [0, 0, 1, 1], - projection="3d", - xlim=(-25, 25), - ylim=(-35, 35), - zlim=(5, 55) + [0, 0, 1, 1], projection="3d", xlim=(-25, 25), ylim=(-35, 35), zlim=(5, 55) ) ax.set_box_aspect((1, 1, 1)) ax.view_init(30, 0) @@ -90,5 +86,5 @@ def animate(i): dpi=200, bitrate=1000, codec="libx264", - extra_args=["-crf", "10"], + extra_args=["-crf", "10", "-pix_fmt", "yuv420p"], ) diff --git a/src/misc/modulargroup.py b/src/misc/modulargroup.py old mode 100755 new mode 100644 index 598a0a2..25eff5b --- a/src/misc/modulargroup.py +++ b/src/misc/modulargroup.py @@ -114,10 +114,8 @@ class HyperbolicDrawing(cairo.Context): """ def set_axis(self, **kwargs): - surface = self.get_target() - width = surface.get_width() - height = surface.get_height() - + width = kwargs.get("width", 800) + height = kwargs.get("height", 400) xlim = kwargs.get("xlim", [-2, 2]) x_min, x_max = xlim ylim = kwargs.get("ylim", [0, 2]) @@ -183,9 +181,11 @@ def main(width, height, depth, xlim=None, ylim=None): xlim = [-2, 2] if ylim is None: ylim = [0, 2] - surface = cairo.ImageSurface(cairo.FORMAT_RGB24, width, height) + surface = cairo.SVGSurface("modulargroup.svg", width, height) ctx = HyperbolicDrawing(surface) - ctx.set_axis(xlim=xlim, ylim=ylim, background_color=(1, 1, 1)) + ctx.set_axis( + width=width, height=height, xlim=xlim, ylim=ylim, background_color=(1, 1, 1) + ) ctx.set_line_join(2) # draw the x-axis ctx.move_to(xlim[0], 0) @@ -207,11 +207,13 @@ def main(width, height, depth, xlim=None, ylim=None): triangle, facecolor=fc_color, linewidth=0.04 / (len(word) + 1) ) - surface.write_to_png("modulargroup.png") + surface.finish() - surface = cairo.ImageSurface(cairo.FORMAT_RGB24, width, height) + surface = cairo.SVGSurface("cayleygraph.svg", width, height) ctx = HyperbolicDrawing(surface) - ctx.set_axis(xlim=xlim, ylim=ylim, background_color=(1, 1, 1)) + ctx.set_axis( + width=width, height=height, xlim=xlim, ylim=ylim, background_color=(1, 1, 1) + ) ctx.set_line_join(2) # draw the x-axis ctx.move_to(xlim[0], 0) @@ -237,7 +239,7 @@ def main(width, height, depth, xlim=None, ylim=None): linewidth=0.02 / (1 + len(word)), ) - surface.write_to_png("cayley_graph.png") + surface.finish() if __name__ == "__main__":