Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Added 3D Mobject :class:`~.Dot3D` (#1097)

Darylgoldenf98cb1eadc2d
diff --git a/manim/constants.py b/manim/constants.py
index f97b7aee4..42babcf4f 100644
--- a/manim/constants.py
+++ b/manim/constants.py
@@ -86,6 +86,10 @@ DR: np.ndarray = DOWN + RIGHT
# Geometry
START_X: int = 30
START_Y: int = 20
+DEFAULT_DOT_RADIUS = 0.08
+DEFAULT_SMALL_DOT_RADIUS = 0.04
+DEFAULT_DASH_LENGTH = 0.05
+DEFAULT_ARROW_TIP_LENGTH = 0.35
# Default buffers (padding)
SMALL_BUFF: float = 0.1
diff --git a/manim/mobject/geometry.py b/manim/mobject/geometry.py
index 4d58ea44b..b2b1f70ef 100644
--- a/manim/mobject/geometry.py
+++ b/manim/mobject/geometry.py
@@ -80,11 +80,6 @@ from ..utils.space_ops import rotate_vector
from ..utils.color import *
from .. import logger
-DEFAULT_DOT_RADIUS = 0.08
-DEFAULT_SMALL_DOT_RADIUS = 0.04
-DEFAULT_DASH_LENGTH = 0.05
-DEFAULT_ARROW_TIP_LENGTH = 0.35
-
class TipableVMobject(VMobject):
"""
diff --git a/manim/mobject/three_dimensions.py b/manim/mobject/three_dimensions.py
index 03877fdac..4625a9610 100644
--- a/manim/mobject/three_dimensions.py
+++ b/manim/mobject/three_dimensions.py
@@ -4,6 +4,7 @@ __all__ = [
"ThreeDVMobject",
"ParametricSurface",
"Sphere",
+ "Dot3D",
"Cube",
"Prism",
"Cone",
@@ -160,6 +161,38 @@ class Sphere(ParametricSurface):
return np.array([np.cos(v) * np.sin(u), np.sin(v) * np.sin(u), np.cos(u)])
+class Dot3D(Sphere):
+ """A spherical dot.
+
+ Parameters
+ --------
+ radius : :class:`float`, optional
+ The radius of the dot.
+ color : :class:`~.Colors`, optional
+ The color of the :class:`Dot3D`
+
+ Examples
+ --------
+
+ .. manim:: Dot3DExample
+ :save_last_frame:
+
+ class Dot3DExample(ThreeDScene):
+ def construct(self):
+ self.set_camera_orientation(phi=75*DEGREES, theta=-45*DEGREES)
+
+ axes = ThreeDAxes()
+ dot_1 = Dot3D(color=RED).move_to(axes.coords_to_point(0, 0, 1))
+ dot_2 = Dot3D(radius=0.1, color=BLUE).move_to(axes.coords_to_point(2, 0, 0))
+
+ self.add(axes, dot_1, dot_2)
+ """
+
+ def __init__(self, radius=DEFAULT_DOT_RADIUS, color=WHITE, **kwargs):
+ Sphere.__init__(self, radius=radius, **kwargs)
+ self.set_color(color)
+
+
class Cube(VGroup):
def __init__(
self,
diff --git a/tests/control_data/graphical_units_data/threed/Dot3DTest.npz b/tests/control_data/graphical_units_data/threed/Dot3DTest.npz
new file mode 100644
index 000000000..4f1c6446e
Binary files /dev/null and b/tests/control_data/graphical_units_data/threed/Dot3DTest.npz differ
diff --git a/tests/test_graphical_units/test_threed.py b/tests/test_graphical_units/test_threed.py
index b48b4d401..1cd883c2b 100644
--- a/tests/test_graphical_units/test_threed.py
+++ b/tests/test_graphical_units/test_threed.py
@@ -15,6 +15,11 @@ class SphereTest(ThreeDScene):
self.play(Animation(Sphere()))
+class Dot3DTest(ThreeDScene):
+ def construct(self):
+ self.play(Animation(Dot3D()))
+
+
class ConeTest(ThreeDScene):
def construct(self):
self.play(Animation(Cone()))