From 2317a7d982f68fc3a03c70d857309e6cf938cc87 Mon Sep 17 00:00:00 2001 From: Grant Sanderson Date: Tue, 9 Jun 2020 21:24:42 -0700 Subject: [PATCH] Torus --- manimlib/mobject/three_dimensions.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/manimlib/mobject/three_dimensions.py b/manimlib/mobject/three_dimensions.py index fed060e1..4093b884 100644 --- a/manimlib/mobject/three_dimensions.py +++ b/manimlib/mobject/three_dimensions.py @@ -1,3 +1,5 @@ +import math + from manimlib.constants import * from manimlib.mobject.types.surface import ParametricSurface from manimlib.mobject.types.surface import SGroup @@ -93,6 +95,19 @@ class Cylinder(ArglessSurface): return [np.cos(u), np.sin(u), v] +class Torus(ArglessSurface): + CONFIG = { + "u_range": (0, TAU), + "v_range": (0, TAU), + "r1": 3, + "r2": 1, + } + + def uv_func(self, u, v): + P = np.array([math.cos(u), math.sin(u), 0]) + return (self.r1 - self.r2 * math.cos(v)) * P - math.sin(v) * OUT + + class Line3D(Cylinder): CONFIG = { "width": 0.05,