2
2
import numpy as np
3
3
4
4
5
- def klein_sphere_points (num_points , radius = 1 ):
5
+ def klein_sphere_points (num_points , radius = 1 ):
6
6
"""
7
7
Generate points on a Klein sphere.
8
8
@@ -13,8 +13,8 @@ def klein_sphere_points(num_points, radius = 1):
13
13
- points: Array of points on the Klein sphere.
14
14
"""
15
15
# Generate random points on a 2D plane
16
- theta = np .random .uniform (0 , 2 * np .pi , num_points )
17
- phi = np .random .uniform (0 , 2 * np .pi , num_points )
16
+ theta = np .random .uniform (0 , 2 * np .pi , num_points )
17
+ phi = np .random .uniform (0 , 2 * np .pi , num_points )
18
18
19
19
# Parametric equations for a Klein sphere
20
20
x = radius * (np .cos (theta ) * (1 + np .sin (phi )))
@@ -34,7 +34,7 @@ def plot_klein_sphere(points):
34
34
fig = plt .figure ()
35
35
ax = fig .add_subplot (111 , projection = "3d" )
36
36
37
- ax .scatter (points [:,0 ], points [:,1 ], points [:,2 ], c = "r" , marker = "o" )
37
+ ax .scatter (points [:, 0 ], points [:, 1 ], points [:, 2 ], c = "r" , marker = "o" )
38
38
39
39
ax .set_xlabel ("X" )
40
40
ax .set_ylabel ("Y" )
@@ -44,38 +44,42 @@ def plot_klein_sphere(points):
44
44
45
45
plt .show ()
46
46
47
+
47
48
# Generate points on the Klein sphere
48
49
num_points = 1000
49
- scales = [0.5 ,1 , 0.5 ]
50
+ scales = [0.5 , 1 , 0.5 ]
50
51
points = klein_sphere_points (num_points , scales )
51
52
52
53
# Plot the generated points
53
54
plot_klein_sphere (points )
54
55
55
- #https://mathworld.wolfram.com/KleinBottle.html
56
- #Klein Bagel
56
+ # https://mathworld.wolfram.com/KleinBottle.html
57
+ # Klein Bagel
58
+
57
59
58
60
def klein_bottle_points (num_points , scale = 1 ):
59
- u = np .linspace (0 , 2 * np .pi , num_points )
60
- v = np .linspace (0 , 2 * np .pi , num_points )
61
+ u = np .linspace (0 , 2 * np .pi , num_points )
62
+ v = np .linspace (0 , 2 * np .pi , num_points )
61
63
U , V = np .meshgrid (u , v )
62
64
63
- X = (scale + np .cos (U / 2 ) * np .sin (V ) - np .sin (U / 2 ) * np .sin (2 * V ))* np .cos (U )
64
- Y = (scale + np .cos (U / 2 ) * np .sin (V ) - np .sin (U / 2 ) * np .sin (2 * V ))* np .sin (U )
65
- Z = np .sin (U / 2 ) * np .sin (V ) + np .cos (U / 2 ) * np .sin (2 * V )
65
+ X = (scale + np .cos (U / 2 ) * np .sin (V ) - np .sin (U / 2 ) * np .sin (2 * V )) * np .cos (U )
66
+ Y = (scale + np .cos (U / 2 ) * np .sin (V ) - np .sin (U / 2 ) * np .sin (2 * V )) * np .sin (U )
67
+ Z = np .sin (U / 2 ) * np .sin (V ) + np .cos (U / 2 ) * np .sin (2 * V )
66
68
return X , Y , Z
67
69
70
+
68
71
def plot_klein_bottle (X , Y , Z ):
69
72
fig = plt .figure ()
70
73
ax = fig .add_subplot (111 , projection = "3d" )
71
- ax .plot_surface (X , Y , Z , cmap = "viridis" , alpha = 0.7 )
74
+ ax .plot_surface (X , Y , Z , cmap = "viridis" , alpha = 0.7 )
72
75
73
76
ax .set_xlabel ("X" )
74
77
ax .set_ylabel ("Y" )
75
78
ax .set_zlabel ("Z" )
76
79
ax .set_title ("Klein Bottle" )
77
80
plt .show ()
78
81
82
+
79
83
# Example usage
80
84
num_points = 100
81
85
scale = 3
0 commit comments