【发布时间】:2022-07-09 13:07:41
【问题描述】:
我希望能够使用 Manim 沿圆弧移动一对向量(径向和切线)。这需要移动和旋转操作。我做到了:
from manim import *
import numpy as np
import math
class basis( Scene ):
def construct( self ):
axes = Axes( x_range = [0, 1, 1], y_range = [0, 1, 1], x_length = 4, y_length = 4,
axis_config = {"include_tip": True, "numbers_to_exclude": [0]} ).add_coordinates()
pc = lambda t: axes.coords_to_point( np.cos( t * 0.5 * PI ), np.sin( t * 0.5 * PI ) )
xone = pc(0)
t_parameter = ValueTracker(0)
e1 = Arrow( start = xone, end = xone + RIGHT, color = GREEN, buff = 0 ).add_updater(
lambda mob: mob.move_to( pc( t_parameter.get_value() ) ) #.rotate( t_parameter.get_value() * PI / 2 )
).update()
e2 = Arrow( start = xone, end = xone + UP, color = GREEN, buff = 0 ).add_updater(
lambda mob: mob.move_to( pc( t_parameter.get_value() ) )
).update()
g1 = ParametricFunction( pc,
t_range=[0, 1],
scaling=axes.x_axis.scaling, color=YELLOW )
self.add( VGroup( axes, g1, e1, e2 ) )
self.play( UpdateFromAlphaFunc( t_parameter,
lambda mob, alpha: mob.set_value( alpha ) ),
run_time=6 )
self.wait( )
有几个问题:
- 我在 updater() 中编码的 move_to 移动了箭头的中心,但我希望该移动应用于终点。
- 我想对该箭头应用旋转(围绕它的终点而不是中心旋转箭头)。
如果我在 updater() 中包含(被注释掉的)rotate(),它会越来越快地旋转箭头,因为旋转不是从原始位置绝对的,而且我不知道之前的 alpha值是更新程序上次运行的时间。
有什么方法可以让我在更新程序中重置箭头的开始、结束值,就好像我正在构造一个新的 Arrow() 来替换动画中每个点的原始值?
【问题讨论】:
标签: animation coordinates manim