0

我无法在轴上画一条水平线。我在轴上做了一个点,但我不知道如何从该点在 x 或 y 轴上画一条线,甚至不知道如何在两点之间画出距离。知道怎么做吗?

from manimlib.imports import *

class GraphX(GraphScene):
    CONFIG ={
        'x_min': -4,
        'x_max': 4,
        'y_min': -2,
        'y_max': 2,
        'x_axis_label': '$x$',
        'y_axis_label': '$y$',
        'graph_origin': 0.5 * DOWN + 0 * LEFT,
    }

def show_function_graph(self):
    self.setup_axes(animate = True)
    text = TextMobject('(x,y)')
    text.shift(2*UP+3*RIGHT)
    self.play(Write(text))
    self.wait(3)

def construct(self):
    self.show_function_graph()
4

1 回答 1

0

图形坐标和屏幕坐标不同步,您必须使用 coord_to_point 和 points_to_coords 在它们之间进行转换

这是一个例子

class GraphX(GraphScene):
    CONFIG ={
        'x_min': -4, 'x_max': 4,
        'y_min': -2, 'y_max': 2,
        'x_axis_label': '$x$', 'y_axis_label': '$y$',
        # 'graph_origin': 0.5 * DOWN + 0 * LEFT,
        'graph_origin': ORIGIN
    }

    def draw_graph(self): self.setup_axes(animate = True)

    def construct(self):
        self.draw_graph()

        # dot = Dot(self.coords_to_point(x=1,y=1))
        dot = Dot(self.coords_to_point(1,1))
        self.play(ShowCreation(dot))
        text = Text('(x,y)')
        text.shift(dot.arc_center+0.5*UR)
        self.play(ShowCreation(text))
        self.wait()

        hl = Line( self.coords_to_point(1,1), self.coords_to_point(0,1))
        vl = Line( self.coords_to_point(1,1), self.coords_to_point(1,0))
        self.play(ShowCreation(hl), ShowCreation(vl))
        self.wait(3)
于 2020-07-03T15:07:03.290 回答