Created
April 21, 2024 07:25
-
-
Save Michaelgathara/4f3874d3c3219bd2fe21255984f54d82 to your computer and use it in GitHub Desktop.
Klein Bottle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# sudo apt install -y && sudo apt-get -y install libcogl-pango-dev && pip install manim | |
from manim import * | |
from math import * | |
class KleinBottle(ThreeDScene): | |
def construct(self): | |
def klein_bottle(u, v): | |
u = u * 2 * PI | |
v = v * 2 * PI | |
half = (u < PI) | |
if half: | |
x = 3 * cos(u) * (1 + sin(u)) + (2 * (1 - cos(u) / 2)) * cos(u) * cos(v) | |
y = 8 * sin(u) + (2 * (1 - cos(u) / 2)) * sin(u) * cos(v) | |
else: | |
x = 3 * cos(u) * (1 + sin(u)) + (2 * (1 - cos(u) / 2)) * cos(v + PI) | |
y = 8 * sin(u) | |
z = -2 * (1 - cos(u) / 2) * sin(v) | |
return np.array([x, y, z]) | |
surface = Surface( | |
lambda u, v: klein_bottle(u, v), | |
u_range=[0, 1], | |
v_range=[0, 1], | |
resolution=(50, 50) | |
).scale(0.2) | |
self.set_camera_orientation(phi=75 * DEGREES, theta=30 * DEGREES) | |
self.begin_ambient_camera_rotation(rate=0.2) | |
self.add(surface) | |
self.wait(10) | |
if __name__ == "__main__": | |
scene = KleinBottle() | |
scene.render() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment