如何使用 tikzpicture 环境在交点处绘制 90 度角

如何使用 tikzpicture 环境在交点处绘制 90 度角

请考虑这个MWE:

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\pgfplotsset{soldot/.style={color=black,only marks,mark=*}}
\pgfplotsset{holdot/.style={color=red,fill=white,very thick,only marks,mark=*}}

\begin{document}

\begin{center}  
\begin{tikzpicture}
    \begin{axis}[
        legend pos=outer north east,
        axis lines = center,
        axis equal,
        xticklabel style = {font=\tiny},
        yticklabel style = {font=\tiny},
        xlabel = $x$,
        ylabel = $y$,
        clip=false,
        legend style={cells={align=left}},
        legend cell align={left}
    ]
    \addplot[thick,samples=80] {-x/abs(x)^(2/3)};    % From https://tex.stackexchange.com/a/144463/152550
    \addplot[thick,samples=80] ({sqrt(16/3)*cos((x) r)}, {sqrt(16)*sin((x) r)});
    \end{axis}
\end{tikzpicture}
\end{center}

\end{document}

阴谋

我想90在两个截距点处画一个度角:

90 度角

函数为y^3 = xx^2/(16/3)+y^2/(16)=1

谢谢!

编辑。谢谢Ruixi 的有用评论查找函数中的错误y^3=x

答案1

这里提出了 2 个绘制直角的宏。

它们有 3 个强制参数:交点和两条路径的名称。可选参数用于传输 tikz 选项。我本来想将它们组合成一个宏,但没有成功。

他们使用tikz 的intersectionscalc库。

% require \usetikzlibrary{intersections,calc}
\newcommand{\rightangleA}[4][]{
\begin{scope}
\path[name path=#2#3#4](#2) circle(6pt);
\path[name intersections={of=#2#3#4 and #3,name=i1}];
\path[name intersections={of=#2#3#4 and #4,name=i2}];
\draw[#1] (i1-1)to($(i1-1)+(i2-1)-(#2)$)to(i2-1)to(#2);
\end{scope}
}
\newcommand{\rightangleB}[4][]{
\begin{scope}
\path[name path=#2#3#4](#2) circle(6pt);
\path[name intersections={of=#2#3#4 and #3,name=i1}];
\path[name intersections={of=#2#3#4 and #4,name=i2}];
\draw[#1] (i1-2)to($(i1-2)+(i2-1)-(#2)$)to(i2-1)to(#2);
\end{scope}
}

宏

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{tikz,pgfplots}
\usetikzlibrary{intersections,calc}
\pgfplotsset{compat=1.8}
\pgfplotsset{soldot/.style={color=black,only marks,mark=*}}
\pgfplotsset{holdot/.style={color=red,fill=white,very thick,only marks,mark=*}}

\newcommand{\rightangleA}[4][]{
\begin{scope}
\path[name path=#2#3#4](#2) circle(6pt);
\path[name intersections={of=#2#3#4 and #3,name=i1}];
\path[name intersections={of=#2#3#4 and #4,name=i2}];
\draw[#1] (i1-1)to($(i1-1)+(i2-1)-(#2)$)to(i2-1)to(#2);
\end{scope}
}
\newcommand{\rightangleB}[4][]{
\begin{scope}
\path[name path=#2#3#4](#2) circle(6pt);
\path[name intersections={of=#2#3#4 and #3,name=i1}];
\path[name intersections={of=#2#3#4 and #4,name=i2}];
\draw[#1] (i1-2)to($(i1-2)+(i2-1)-(#2)$)to(i2-1)to(#2);
\end{scope}
}

\begin{document}

\begin{center}  
\begin{tikzpicture}
    \begin{axis}[
        legend pos=outer north east,
        axis lines = center,
        axis equal,
        xticklabel style = {font=\tiny},
        yticklabel style = {font=\tiny},
        xlabel = $x$,
        ylabel = $y$,
        clip=false,
        legend style={cells={align=left}},
        legend cell align={left}
    ]
    \addplot[thick,samples=80,name path=A] {-x/abs(x)^(2/3)};    % From https://tex.stackexchange.com/a/144463/152550
    \addplot[thick,samples=80,name path=B] ({sqrt(16/3)*cos((x) r)}, {sqrt(16)*sin((x) r)});
    \path[name intersections={of=A and B,by={c,d}}];% intersections of paths
    \rightangleA{c}{A}{B}
    \rightangleB[blue]{c}{A}{B}
    \rightangleA[fill=red,thick]{d}{A}{B}
    %\rightangleB{d}{A}{B}
    \end{axis}
\end{tikzpicture}
\end{center}

\end{document}

答案2

对我来说这是另一项数学练习!如下所示:

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\pgfplotsset{soldot/.style={color=black,only marks,mark=*}}
\pgfplotsset{holdot/.style={color=red,fill=white,very thick,only marks,mark=*}}

\begin{document}

\begin{center}  
\begin{tikzpicture}
    \begin{axis}[
        legend pos=outer north east,
        axis lines = center,
        axis equal,
        xticklabel style = {font=\tiny},
        yticklabel style = {font=\tiny},
        xlabel = $x$,
        ylabel = $y$,
        clip=false,
        legend style={cells={align=left}},
        legend cell align={left}
    ]
    \addplot[thick,samples=80] {(-3)*x/abs(x)*abs(x)^(1/3)};    % From https://tex.stackexchange.com/a/144463/152550
    \addplot[thick,samples=80] ({sqrt(16/3)*cos((x) r)}, {sqrt(16)*sin((x) r)});
    \pgfmathsetmacro\intersectionx{-1.3157310986}
    \pgfmathsetmacro\intersectiony{3.2873325096}
    \pgfmathsetmacro\intersectionangle{%
      atan((-2*\intersectionx/(16/3))/(2*\intersectiony/16))
    }
    \pgfmathsetmacro\cornersidelength{0.3}
    \filldraw (axis cs:\intersectionx,\intersectiony) circle (1pt);
    \draw[thick]
      (axis cs:{\intersectionx
                -\cornersidelength*sin(\intersectionangle)},
               {\intersectiony
                +\cornersidelength*cos(\intersectionangle)}) --
      (axis cs:{\intersectionx
                -\cornersidelength*sin(\intersectionangle)
                +\cornersidelength*cos(\intersectionangle)},
               {\intersectiony
                +\cornersidelength*cos(\intersectionangle)
                +\cornersidelength*sin(\intersectionangle)}) --
      (axis cs:{\intersectionx
                +\cornersidelength*cos(\intersectionangle)},
               {\intersectiony
                +\cornersidelength*sin(\intersectionangle)});
    \filldraw (axis cs:-\intersectionx,-\intersectiony) circle (1pt);
    \draw[thick]
      (axis cs:{-\intersectionx
                +\cornersidelength*cos(\intersectionangle)},
               {-\intersectiony
                +\cornersidelength*sin(\intersectionangle)}) --
      (axis cs:{-\intersectionx
                +\cornersidelength*cos(\intersectionangle)
                +\cornersidelength*sin(\intersectionangle)},
               {-\intersectiony
                +\cornersidelength*sin(\intersectionangle)
                -\cornersidelength*cos(\intersectionangle)}) --
      (axis cs:{-\intersectionx
                +\cornersidelength*sin(\intersectionangle)},
               {-\intersectiony
                -\cornersidelength*cos(\intersectionangle)});
    \end{axis}
\end{tikzpicture}
\end{center}

\end{document}

直角


那么,这幅画背后的数学魔法是什么呢?当然,你需要自己找出交叉点的坐标,这是上述解决方案的一个缺点。推导如下:

衍生词

答案3

当计算轴内和轴外定义的一些路径的交点时,会产生一些奇怪的效果,所以我只能使用一个丑陋的解决方案,其中的因子1.11.13是硬编码的。如果没有这些影响,我们可以得到一个更好的解决方案,它不依赖于用户的任何计算……

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{calc,intersections}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usepgfplotslibrary{fillbetween}

\begin{document}
\begin{tikzpicture}
 \begin{axis}[
        legend pos=outer north east,
        axis lines = center,
        axis equal,
        xticklabel style = {font=\tiny},
        yticklabel style = {font=\tiny},
        xlabel = $x$,
        ylabel = $y$,
        clip=false,
        legend style={cells={align=left}},
        legend cell align={left}
    ]
    \addplot[thick,samples=80,name path=A] {(-3)*x/abs(x)^(2/3)};    % From https://tex.stackexchange.com/a/144463/152550
    \addplot[thick,samples=80,name path=B] ({sqrt(16/3)*cos((x) r)}, {sqrt(16)*sin((x) r)});
    \path[name intersections={of=A and B}] (0,0) coordinate (O) (1,0)
    coordinate(X);
   \end{axis}
    \path 
    let \p1=($(X)-(O)$),\p2=($(intersection-1)-(O)$),\n1={\x2/\x1},
    \n2={-1/(pow(abs(\n1),2/3))} in 
    (intersection-1) -- + (-0.3,{-0.3*\n2*1cm/1pt}) coordinate(aux1)
    (intersection-1) -- + ({-0.3*\n2*1cm/1pt},0.3) coordinate(aux2)
    (intersection-1) -- + ({-0.3cm-0.3*\n2*1cm/1pt},{0.3cm-0.3*\n2*1cm/1pt}) coordinate(aux3);
    \path[draw=red] (aux3) -- ($(aux3)+1.13*($(aux2)-(aux3)$)$);
    \path[draw=red] (aux3) -- ($(aux3)+1.1*($(aux1)-(aux3)$)$);
    \path 
    let \p1=($(X)-(O)$),\p2=($(intersection-2)-(O)$),\n1={\x2/\x1},
    \n2={-1/(pow(abs(\n1),2/3))} in 
    (intersection-2) -- + (0.3,{0.3*\n2*1cm/1pt}) coordinate(aux1)
    (intersection-2) -- + ({0.3*\n2*1cm/1pt},-0.3) coordinate(aux2)
    (intersection-2) -- + ({0.3cm+0.3*\n2*1cm/1pt},{-0.3cm+0.3*\n2*1cm/1pt}) coordinate(aux3);
    \path[draw=red] (aux3) -- ($(aux3)+1.13*($(aux2)-(aux3)$)$);
    \path[draw=red] (aux3) -- ($(aux3)+1.1*($(aux1)-(aux3)$)$);
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容