0

I would like to express the angle of rotation for the tangent line in terms of atan x using the slope (which is calculated earlier in the problem). I can get it to work using the angle but I do not want to have to calculate it by hand first. I would like the black line to end up where the red line is using a calculation that's similar to the black line.

\documentclass[tikz]{standalone}
\begin{document}
    \begin{tikzpicture}[xscale=0.4, yscale=0.1]
    % draw axis
    \draw (-1.5,0) -- (6.5,0);
    \draw (0,-10) -- (0,15);

    % plot f(x)
    \draw [domain=(-1:6)] plot (\x,\x*\x-3*\x-4);

    % plot secant line
    \draw[dashed] (-1,0) -- (6,14);

    % plot tangent line
    \draw [rotate around={{180*atan(2)/pi}:(2.5,-5.25)}] (-2,-5.25) -- (7,-5.25); 
    \draw [red, rotate around={{63.43}:(2.5,-5.25)}] (-2,-5.25) -- (7,-5.25); 

    % plot cirles as points
    \foreach \x/\y in {-1/0,2.5/-5.25,6/14}{\draw [fill=black] (\x,\y) ellipse (0.1cm and 0.4cm);}
\end{tikzpicture}

\end{document}

TIA.

1 Answers1

1

To debug the issue, just use \pgfmathparse... \pgfmathresult to print out the value of the formula, you'll see the problem immediately:

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\pgfmathparse{180*atan(2)/pi}\pgfmathresult
\end{document}

prints out 3634.56235 while you want some value around 63. Changing it to just atan(2) gives the desired result.

Explanation, TikZ uses degrees instead of radians by default for trigonometric functions → Incorrect plot using pgfplots (trigonometric functions like cos, sin and tan) - TeX - LaTeX Stack Exchange.

Anyway, the fix is simply

%!TEX TS-program = xelatex
\documentclass[tikz]{standalone}
\begin{document}
    \begin{tikzpicture}[xscale=0.4, yscale=0.1]
    % draw axis
    \draw (-1.5,0) -- (6.5,0);
    \draw (0,-10) -- (0,15);

    % plot f(x)
    \draw [domain=(-1:6)] plot (\x,\x*\x-3*\x-4);

    % plot secant line
    \draw[dashed] (-1,0) -- (6,14);

    % plot tangent line
    \draw [rotate around={{atan(2)}:(2.5,-5.25)}] (-2,-5.25) -- (7,-5.25); 
    \draw [red, rotate around={{63.43}:(2.5,-5.25)}] (-2,-5.25) -- (7,-5.25); 

    % plot cirles as points
    \foreach \x/\y in {-1/0,2.5/-5.25,6/14}{\draw [fill=black] (\x,\y) ellipse (0.1cm and 0.4cm);}
\end{tikzpicture}

\end{document}

user202729
  • 7,143