Skip to content

Add ThreeDValueTracker class to value_tracker.py file#4628

Open
GoThrones wants to merge 12 commits intoManimCommunity:mainfrom
GoThrones:add-threedvaluetracker
Open

Add ThreeDValueTracker class to value_tracker.py file#4628
GoThrones wants to merge 12 commits intoManimCommunity:mainfrom
GoThrones:add-threedvaluetracker

Conversation

@GoThrones
Copy link
Contributor

@GoThrones GoThrones commented Mar 6, 2026

Overview: What does this pull request change?

It adds a new class named ThreeDValueTracker.

Motivation and Explanation: Why and how do your changes improve the library?

In the existing file of value_tracker.py, there were only 2 classes: one was ValueTracker, which was supposedly to be used for 2D scenes, wherein only one of the number needs to continuously change w.r.t time. Another class was ComplexValueTracker which also works in 2D scenes and allows users to change 2 numbers continuously w.r.t time. However, there was nothing to allow users working in 3D scenes to changes 3 numbers simultaneously w.r.t time.

Example code which allows users to use ThreeDValueTracker:

class testThreeDValueTracker(ThreeDScene):
    def construct(self):
        self.set_camera_orientation(**self.default_angled_camera_orientation_kwargs)
        axes = ThreeDAxes().add_coordinates()
        for axis,color in zip(axes.get_axes(),[RED, GREEN, BLUE]):
            axis.set_color(color)
        self.add(axes)
        position = ThreeDValueTracker([-3,0,0])
        s = Sphere(radius = 0.1).set_color(GOLD)
        s.move_to(axes.c2p(position.get_value()))
        self.add(s)
        self.begin_ambient_camera_rotation(rate=1.5)
        self.wait(2)
        s.add_updater(lambda m: m.move_to(axes.c2p(position.get_value())))
        self.play(position.animate(run_time = 2).set_value([0,3,4]))
        self.wait()                    
        self.play(position.animate(run_time = 2).set_value([-2,0,-4]))
        self.wait()
        self.play(position.animate(run_time = 2).set_value([2,0,0]))
        self.wait()

Output video:

testThreeDValueTracker.mp4

Reviewer Checklist

  • The PR title is descriptive enough for the changelog, and the PR is labeled correctly
  • If applicable: newly added non-private functions and classes have a docstring including a short summary and a PARAMETERS section
  • If applicable: newly added functions and classes are tested

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant