The DecimalNumber doesn't rotate with its family(VGroup) In ThreeDScene
- Langage dominant
- Python
- Étoiles
- 93.8k
- Forks
- 7.7k
- Métriques de merge des PR
- Métriques de PR en attente
Description
Hi, everyone. I want to make a VGroup(it contains DecimalNumber) rotate to the positive y-axis.
```
class ThreeDTest(ThreeDScene):
CONFIG = {
"x_min":-5,
"x_max": 5,
"y_min":-5,
"y_max": 5,
"z_min":-5,
"z_max": 5,
}
def construct(self):
axes = ThreeDAxes()
self.add(axes)
self.set_camera_orientation(phi=60 * DEGREES, theta=45 * DEGREES)
# angle counter
degree = TextMobject(
"Angle:",
tex_to_color_map={"Angle:":GREEN}
).scale(0.8)
degreeNum = DecimalNumber(0, num_decimal_places=0)
# put the angle next to degreeNum left side
degree.next_to(degreeNum, LEFT)
# time object used to count
time = ValueTracker(0)
degreeNum.add_updater(lambda num:num.set_value(time.get_value()))
# rotate the group to the positive y-axis
angleGroup = VGroup(degree, degreeNum)
angleGroup.move_to(UP * 2 + OUT / 2)
angleGroup.rotate(PI / 2, axis=RIGHT)
angleGroup.rotate(PI / 2, axis=OUT)
# a dot for showing angle chaning
testDot = Dot(np.array((1, 0, 0)))
self.add(degreeNum)
self.play(Write(degree))
self.play(
Rotate(testDot, PI / 6, run_time=3, about_point=ORIGIN),
ApplyMethod(time.increment_value, 30.0, rate_func=smooth, run_time=3)
)
```
But i got a **unexpected** result:

So i wanted to fix it. I asked the @saturnman for help, and he say that maybe is a **bug**. Here is the **solution**
#### 1) Write right function
```
def numUpdater(num):
center = num.get_center()
num.set_value(time.get_value())
num.move_to(ORIGIN)
num.rotate(PI / 2, axis=RIGHT)
num.rotate(PI / 2, axis=OUT)
num.move_to(center)
degreeNum.add_updater(numUpdater)
```
In this function we need to rotate it to the right place, and ```set_value()```.
#### 2) Delete the code
In ```manimlib\mobject\numbers.py\set_value``` function. We need to delete the following code
```
# new_decimal.scale(
# self[-1].get_height() / new_decimal[-1].get_height()
# )
```
Finally, i got the right result

Thanks to saturnman
#### FULL CODE:
```
class ThreeDTest(ThreeDScene):
CONFIG = {
"x_min":-5,
"x_max": 5,
"y_min":-5,
"y_max": 5,
"z_min":-5,
"z_max": 5,
}
def construct(self):
axes = ThreeDAxes()
self.add(axes)
self.set_camera_orientation(phi=60 * DEGREES, theta=45 * DEGREES)
# angle counter
degree = TextMobject(
"Angle:",
tex_to_color_map={"Angle:":GREEN}
).scale(0.8)
degreeNum = DecimalNumber(0, num_decimal_places=0)
# put the angle next to degreeNum left side
degree.next_to(degreeNum, LEFT)
# time object used to count
time = ValueTracker(0)
def numUpdater(num):
center = num.get_center()
num.set_value(time.get_value())
num.move_to(ORIGIN)
num.rotate(PI / 2, axis=RIGHT)
num.rotate(PI / 2, axis=OUT)
num.move_to(center)
degreeNum.add_updater(numUpdater)
# degreeNum.add_updater(lambda num:num.set_value(time.get_value()))
# rotate the group to the positive y-axis
angleGroup = VGroup(degree, degreeNum)
angleGroup.move_to(UP * 2 + OUT / 2)
angleGroup.rotate(PI / 2, axis=RIGHT)
angleGroup.rotate(PI / 2, axis=OUT)
# a dot for showing angle chaning
testDot = Dot(np.array((1, 0, 0)))
self.add(degreeNum)
self.play(Write(degree))
self.play(
Rotate(testDot, PI / 6, run_time=3, about_point=ORIGIN),
ApplyMethod(time.increment_value, 30.0, rate_func=smooth, run_time=3)
)
```
Here is the environment
- System: Windows10
- manim version 0.1.10
- Python 3.8
Guide de contribution
Aucun guide de contribution indexé pour ce dépôt
Évaluation
Cette issue n'a pas encore été évaluée.