3b1b / 3b1b/manim

The DecimalNumber doesn't rotate with its family(VGroup) In ThreeDScene

未關閉
#885 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
Python
星號
93.9k
分支
7.7k
平均合併
2 天 13 小時
30 天內合併 PR
4

描述

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:
![ThreeDTest](https://user-images.githubusercontent.com/32706754/74505779-f96f4700-4f32-11ea-9aea-3630b05f40d1.gif)

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
![ThreeDTest (1)](https://user-images.githubusercontent.com/32706754/74506923-f0cc4000-4f35-11ea-89e9-45c9b34a49e6.gif)

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

貢獻指南

這個儲存庫沒有索引到貢獻指南

研究方向

這個問題位於 manimlib/mobject/numbers.py 的 set_value 函式中。查看 DecimalNumber 類別以及它如何更新值。問題是旋轉後進行 scaling 會破壞 3D 變換。先檢查 set_value 方法和被註解掉的 scaling 行。透過建立一個包含 DecimalNumber 的旋轉 VGroup 的簡單 3D 場景來重現該問題,然後透過移除 scaling 程式碼來驗證修正。

由索引模型根據 Issue 內容生成。

評估

領域
computer-graphics
Issue 類型
缺陷
難度
3/5
預估耗時
1-2 天
活躍度
停滯
描述清晰度
描述清楚
新手友好度
45/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。