如何绘制与抛物线和 x 轴相切的直线?

如何绘制与抛物线和 x 轴相切的直线?

如何绘制与抛物线相切的直线,如下所示:

在此处输入图片描述

我的编码看起来像这样

\begin{figure}[h!]
    \centering
    \begin{tikzpicture}
    \coordinate (1) at (-3,-3);
    \coordinate (2) at (3,3);
    \coordinate (O) at (0,0);

    \draw (-1.5,-3) node[below]{directrix};
    \draw (-1.5,-3.4) node[below]{$x=-a$};
    \draw (O) node[below left]{$(0,0)$};
    \draw [fill=black] (1,0) circle (1.5pt);
    \draw[thick, ->] (-3,0) -- (5,0) node[right]{$x$};
    \draw[thick, ->] (0,-3) -- (0,3) node[above]{$y$};
    \draw[dashed,very thin] (-1.3,-3)--(-1.3,3);
    \draw[mirror=(1)--(2)] (-2,4) parabola bend (0,0) (2,4);
    \draw (1,0) node[below]{$F(a,0)$};
    \draw (0,0) node[above left]{$V$};
    \end{tikzpicture}
\end{figure}

产生 在此处输入图片描述

答案1

您可以使用intersections库来找到抛物线与水平线的交点。(当然,您也可以通过分析来确定该点。)

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections}
\makeatletter
\tikzset{% https://tex.stackexchange.com/a/142491
  mirror/.code={\pgfutil@in@{--}{#1}\ifpgfutil@in@\tikz@trans@mirror#1\@nil
    \else\tikz@scan@one@point\pgftransformmirror#1\relax\fi},
  ymirror/.code={\pgfutil@ifnextchar(\tikz@trans@ymirror@coordinate\tikz@trans@ymirror@simple#1\@nil},
  xmirror/.code={\pgfutil@ifnextchar(\tikz@trans@xmirror@coordinate\tikz@trans@xmirror@simple#1\@nil}}
\def\tikz@trans@mirror#1--#2\@nil{%
  \pgfextract@process\pgf@trans@mirror@A{\tikz@scan@one@point\pgfutil@firstofone#1}%
  \pgfextract@process\pgf@trans@mirror@B{\tikz@scan@one@point\pgfutil@firstofone#2}%
  \pgftransformMirror{\pgf@trans@mirror@A}{\pgf@trans@mirror@B}}
\def\pgftransformxmirror#1{\pgfmathparse{2*(#1)}\pgftransformcm{-1}{0}{0}{1}{\pgfqpoint{+\pgfmathresult pt}{+0pt}}}
\def\pgftransformymirror#1{\pgfmathparse{2*(#1)}\pgftransformcm{1}{0}{0}{-1}{\pgfqpoint{+0pt}{+\pgfmathresult pt}}}
\def\tikz@trans@ymirror@simple#1\@nil{
  \pgfmathparse{#1}\let\tikz@temp\pgfmathresult
  \ifpgfmathunitsdeclared
    \pgftransformymirror{\tikz@temp pt}%
  \else
    \pgf@process{\pgfpointxy{0}{\tikz@temp}}%
    \pgftransformymirror{+\the\pgf@y}%
  \fi}
\def\tikz@trans@xmirror@simple#1\@nil{
  \pgfmathparse{#1}\let\tikz@temp\pgfmathresult
  \ifpgfmathunitsdeclared
    \pgftransformxmirror{\tikz@temp pt}%
  \else
    \pgf@process{\pgfpointxy{\tikz@temp}{0}}%
    \pgftransformxmirror{+\the\pgf@x}%
  \fi}
\def\tikz@trans@xmirror@coordinate#1\@nil{\tikz@scan@one@point\pgfutil@firstofone#1\pgftransformxmirror{+\the\pgf@x}}
\def\tikz@trans@ymirror@coordinate#1\@nil{\tikz@scan@one@point\pgfutil@firstofone#1\pgftransformymirror{+\the\pgf@y}}
\def\pgftransformmirror#1{%
  \pgfpointnormalised{#1}%
  \pgf@xa=\pgf@sys@tonumber\pgf@y\pgf@x
  \pgf@xb=\pgf@sys@tonumber\pgf@x\pgf@x
  \pgf@yb=\pgf@sys@tonumber\pgf@y\pgf@y
  \multiply\pgf@xa2\relax
  \pgf@xc=-\pgf@yb\advance\pgf@xc\pgf@xb
  \pgf@yc=-\pgf@xb\advance\pgf@yc\pgf@yb
  \edef\pgf@temp{{\the\pgf@xc}{+\the\pgf@xa}{+\the\pgf@xa}{+\the\pgf@yc}}%
  \expandafter\pgf@transformcm\pgf@temp{\pgfpointorigin}}
\def\pgftransformMirror#1#2{%
  \pgfextract@process\pgf@trans@mirror@A{#1}%
  \pgfextract@process\pgf@trans@mirror@B{#2}%
  \pgfextract@process\pgf@trans@mirror@g{\pgfpointdiff{\pgf@trans@mirror@A}{\pgf@trans@mirror@B}}%
  \pgftransformshift{\pgf@trans@mirror@A}%
  \pgftransformmirror{\pgf@trans@mirror@g}%
  \pgftransformshift{\pgfpointscale{-1}{\pgf@trans@mirror@A}}}
\makeatother
\begin{document}
\begin{figure}[h!]
    \centering
    \begin{tikzpicture}
    \coordinate (1) at (-3,-3);
    \coordinate (2) at (3,3);
    \coordinate (O) at (0,0);

    \draw (-1.5,-3) node[below]{directrix};
    \draw (-1.5,-3.4) node[below]{$x=-a$};
    \path (O) node[below left]{$(0,0)$} node[above left]{$V$};
    \draw [fill=black] (1,0) coordinate (F) circle (1.5pt)
     node[below]{$F(a,0)$};
    \draw[thick, ->] (-3,0) -- (5,0) node[right]{$x$};
    \draw[thick, ->] (0,-3) -- (0,3) node[above]{$y$};
    \draw[dashed,very thin] (-1.3,-3)--(-1.3,3);
    \draw[mirror=(1)--(2),name path=parabola] (-2,4) parabola bend (0,0) (2,4);
    \path[name path=hori] (-1.3,1.3) -- (current bounding box.east|-0,1.3);
    \draw[name intersections={of=parabola and hori,by=i1}]
     (-1.3,1.3) node[above left]{$N$} -- (i1) node[below right]{$P(x,y)$}
     -- (F);
    \end{tikzpicture}
\end{figure}
\end{document}

在此处输入图片描述

顺便说一句,提供完整的代码总是更好的。我不知道我是否mirror从正确的地方复制了样式。(我不确定我是否理解你在这里需要它。如果只是为了画抛物线,那么它就不需要了,但我假设你还有其他应用程序。

相关内容