tikz 中交叉点的 x 坐标错误

tikz 中交叉点的 x 坐标错误

我想从 向下直行绘制一条线$P*P$与曲线的下部相交,但是当我尝试获取 x 坐标$P*P$并在那里绘制一个红色圆圈时,我最终得到了一个完全不同的点。

我做错了什么?

\documentclass[margin=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usetikzlibrary{calc,intersections,through,backgrounds}

\begin{document}

\begin{tikzpicture}[
        point/.style={
            circle,
            fill=black,
            inner sep=1.5pt,
        },
        ]
\begin{axis}[
        xmin=-4,
        xmax=5,
        ymin=-5,
        ymax=5,
        xlabel={$x$},
        ylabel={$y$},
        scale only axis,
        axis lines=middle,
        domain=-2.279018:3,      
        samples=201,
        smooth,   
        clip=false,
        % use same unit vectors on the axis
        axis equal image=true,
    ]

\addplot[blue,name path=ECU] {sqrt(x^3-3*x+5)} node[right] {$E$};
\addplot[blue,name path=ECL] {-sqrt(x^3-3*x+5)};
\addplot[red,name path=line] {2.621+0.251*(x+1.2)};
\path [name intersections={of=ECU and line,by=E}];
\coordinate (origin) at (0,0);
\coordinate[point, label={right:$P*P$}] (D) at (intersection-4);

\fill[red] let \p1 = (D),  in(\x1,0) circle [radius=2pt];

\draw [fill=black] (axis cs:-1.2,2.6) circle (2pt);
\draw[color=black] (axis cs:-1.4,2.7) node [left]{$P$};

\end{axis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案1

不太清楚会发生什么,但使用垂直坐标可以使这变得更容易一些:

\fill[red] (D|-origin) circle [radius=2pt];

(D|-origin)表示 的x坐标D和 的y坐标origin

答案2

仅供比较,以下是元帖子,我让 MP 帮我完成所有计算,包括使用宏查找函数的正值solve。为了得到切线,我只需沿着曲线选择一个可能的点,然后使用允许您提取特定点处路径“方向”的功能。对于pairMP 中的任何给定变量,xpartypart允许您提取 x 和 y 坐标。

在此处输入图片描述

这已被包裹起来,luamplib因此您需要使用 进行编译lualatex

\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
beginfig(1);
    numeric u;
    u = 1cm;

    % axes and ticks
    path xx, yy, ec_upper, ec_lower;
    xx = (left--right) scaled 4.8u;
    yy = xx rotated 90;

    drawoptions(withcolor 1/4 white);
    drawarrow xx; label.rt ("$x$", point 1 of xx);
    drawarrow yy; label.top("$y$", point 1 of yy);
    for i=-4 step 2 until 4:
        if i <> 0:
            draw (left--right) scaled 3 shifted (0, i*u); label.lft("$" & decimal i & "$", (-3, i*u));
            draw (down--up) scaled 3 shifted (i*u, 0); label.bot("$" & decimal i & "$", (i*u, -3));
        fi
    endfor
    drawoptions();

    % define the function, find a good value for min_x
    vardef f(expr x) = sqrt(x**3 - 3x + 5) enddef;
    vardef fpos(expr x) = (x**3 - 3x + 5) < 0 enddef;
    numeric minx, maxx, s;
    minx = solve.fpos(-3, 0); % see pp.176-177 of the MetafontBook
    maxx = 3; s = 1/32;

    % define and draw the upper and lower parts of the path
    ec_upper = ((minx, 0) for x=minx+s step s until maxx+eps: -- (x, f(x)) endfor) scaled u;
    ec_lower = reverse ec_upper reflectedabout(left, right);

    drawoptions(withcolor 2/3 blue);
    draw ec_lower .. ec_upper;
    label.urt("$E$", point infinity of ec_upper);
    drawoptions();

    % find the tangent at P and the intersection with the upper part of the curve

    path line; pair P, PP; numeric p; 
    p = 34; % I experimented to find this value...

    P = point p of ec_upper;

    line = (left -- 6 right) scaled u 
        rotated angle direction p of ec_upper  % "direction t of path" gives tangent of path at time t
        shifted P;

    PP = line intersectionpoint reverse ec_upper; % reverse so we start at the other end

    % draw the orthogonal markers using "xpart" and "ypart" 
    draw (0, ypart PP) -- PP -- (xpart PP, 0) dashed withdots scaled 1/2;
    filldraw fullcircle scaled dotlabeldiam shifted (xpart PP, 0) withcolor 2/3 red;

    draw line withcolor 1/2 red;
    dotlabel.ulft("$P$", P);
    dotlabel.lrt("$P*P$", PP);

endfig;
\end{mplibcode}
\end{document}

相关内容