我想用manim制作一个视频,其中包括一些直线。
Manim的类Line实际上是线段。将buff属性更改为负值不起作用。我试图计算这条线与屏幕边框的相交,但太复杂了。然后,我像这样扩展了这条线:
def expand_line(line: Line, ratio=100) -> None:
ends = line.get_start_and_end()
delta = ends[1] - ends[0]
line.put_start_and_end_on(ends[0] - ratio * delta, ends[1] + ratio * delta)它运行得很好,但是像Create这样的动画速度太快了。
有什么课程或其他更好的方法来画直线吗?
发布于 2022-08-29 10:46:11
我试图计算行与屏幕边框的相交,但这太复杂了。
你在这里的想法是对的。这是我的解决方案:
class Test(Scene):
def extend_line(self, line: Sequence[np.ndarray], **kwargs):
sr_points = ScreenRectangle(height=config.frame_height).get_vertices()
inters = []
for i in adjacent_pairs(sr_points):
inters += [line_intersection(i, line)]
inters.sort(key=np.linalg.norm) # we want the nearest intersections
return Line(*inters[:2], **kwargs)
def construct(self):
a = self.extend_line([LEFT * 2, UP])
self.wait()
self.play(Create(a))https://stackoverflow.com/questions/73527074
复制相似问题