如何将箭头沿着路径移动,调整终点和方向?
我希望能够使用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值是什么更新者最后运行。
有什么办法可以将箭头启动重置,在更新程序中到位的结束值,就好像我正在构建一个新的箭头()以替换动画中每个点的原始值吗?
I'd like to be able to move a pair of vectors (radial and tangent) along a circular arc using Manim. This requires a move and rotate operation. I got as far as:
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( )
There are a couple problems:
- The move_to that I've coded in the updater() moves the center of the arrow, but I'd like that move to apply to the end point.
- I'd like to apply a rotation to that arrow (rotating the arrow about it's end point, not it's center).
If I include (the commented out) rotate() in my updater(), it spins the arrow faster and faster, since the rotation isn't absolute from the original position, and I don't know what the previous alpha value was when the updater last ran.
Is there any way that I can just reset the arrow start,end values in place in my updater, as if I was constructing a new Arrow() to replace the original at each point in the animation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于箭头从行中继承,因此所有行方法都可用,包括put_start_and_end_on()
Because Arrow inherits from Line, all the Line methods are available, including put_start_and_end_on()