-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Slight offset in MoveAlongPath #3936
Comments
It's not a bug, it's a feature. class MowerAnimation(Scene):
def construct(self):
# Create the mower as a small triangle
mower = Triangle(color=GREEN, fill_opacity=0.5).scale(0.2).scale(3)
start_pos = np.array([-4, -3, 0])
end_pos = np.array([-1, 4, 0])
mower.move_to(start_pos)
delta = end_pos - start_pos
angle = np.arctan2(delta[0], delta[1])
mower.rotate(-angle)
bbox = always_redraw(lambda:
VGroup(
Polygon(*[mower.get_critical_point(p) for p in (UR,UL,DL,DR)],stroke_width=1,stroke_color=YELLOW),
Line(mower.get_critical_point(DOWN),mower.get_critical_point(UP),stroke_width=1,color=YELLOW),
Line(mower.get_critical_point(LEFT),mower.get_critical_point(RIGHT),stroke_width=1,color=YELLOW),
)
)
self.add(bbox)
path = Line(start_pos, end_pos)
dashed_line = DashedLine(start_pos, end_pos)
self.add(dashed_line)
self.play(
MoveAlongPath(mower, path, rate_func=linear),
run_time=5
)
self.wait() MowerAnimation.mp4How to change this?
Somehow I was most curious to try out my third idea there: class MowerAnimation(Scene):
def construct(self):
# Create the mower as a small triangle
mower = VGroup(
Square(stroke_opacity=0.2, fill_opacity=0)
)
tri = Triangle(color=GREEN, fill_opacity=0.5).scale(0.2)
start_pos = np.array([-4, -3, 0])
end_pos = np.array([-1, 4, 0])
mower.move_to(start_pos)
delta = end_pos - start_pos
angle = np.arctan2(delta[0], delta[1])
tri.rotate(-angle).shift(mower.get_center()-tri.get_center_of_mass())
mower += tri
path = Line(start_pos, end_pos)
dashed_line = DashedLine(start_pos, end_pos)
self.add(dashed_line)
self.play(
MoveAlongPath(mower, path, rate_func=linear),
run_time=5
)
self.wait() MowerAnimation.mp4 |
In case you intend to rotate your triangle more often in this script, then you should use |
Thank you, this is very helpful! |
you are welcome. Come over to Discord for more tips about Manim and the details about its workings: |
Description of bug / unexpected behavior
When using MoveAlongPath with a rotated object, a slight offset is introduced
Expected behavior
The object follows the line exactly, not with an offset.
How to reproduce the issue
Minimum Reproducible Code
Additional media files
Logs
Terminal output
System specifications
System Details
``` https://notebooks.gesis.org/binder/jupyter/user/manimcommunity-jupyter_examples-xz4gvrcr/notebooks/First%20Steps%20with%20Manim.ipynb ```The text was updated successfully, but these errors were encountered: