使用 manim 到轴上的点的距离

Distance from a point on axes using manim

我无法在坐标轴上绘制水平线。我在轴上做了一个点,我不知道如何从该点在 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()

图形坐标和屏幕坐标不同步,你必须使用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)