14

I really was working on this now for a long time. I need a tangent line on a parabola; here is my working example:

\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{arrows,calc,intersections,decorations.markings}
\usepackage{relsize}
\begin{document}
\begin{tikzpicture}[
        ]
        \draw[very thick, ->, >=stealth', line join=miter]   (6,0) node(xline)[right] {$x_i$} -|
                          (0,6) node(yline)[above] {$y_i$};
            \draw[blue,thick,name path = line 1]          (4,1) coordinate () parabola (0,3);
            \draw[blue,thick,name path = line 2]         (4,2) coordinate ( ) parabola (0,4);
            \draw[blue,thick,name path = line 3]         (4,3) coordinate ( ) parabola (0,5);
            \draw[dashed ,name path = line 4](1,0) coordinate () -- (1,5);
            \draw[dashed ,name path = line 5](3,0) coordinate () -- (3,5);
            \fill[red,name intersections={of=line 1 and line 4}]     (intersection-1) circle (2pt) node { };
    \end{tikzpicture}
\end{document}

Instead of the red dot I want a tangent line. Does anyone of you know how to do this?

enter image description here

\begin{tikzpicture}[
    tangent/.style={
        decoration={
            markings,% switch on markings
            mark=
                at position #1
                with
                {
                    \coordinate (tangent point-\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}) at (0pt,0pt);
                    \coordinate (tangent unit vector-\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}) at (1,0pt);
                }
        },
        postaction=decorate
    },
    use tangent/.style={
        shift=(tangent point-#1),
        x=(tangent unit vector-#1),
    },
    use tangent/.default=1
]
    \draw[thick, <->, line join = miter->]   (6,0) node(xline)[right] {$x_i$} -|
                      (0,6) node(yline)[above] {$y_i$};
\draw[dashed ,name path = line1](1,0) coordinate () -- (1,5);
\draw [blue,tangent=0.3,name path = line2] (4,1)    parabola  (0,3);
\fill[red,name intersections={of=line1 and line2}]     (intersection-1) circle (2pt) node {};
\draw [orange, thick, use tangent] (-1,0) -- (1,0) ;
\end{tikzpicture}
Gine
  • 141
  • 6
  • 2
    Welcome to TeX.SE. Let us know if any of those questions provided you with a solution you could use. – Peter Grill Sep 28 '12 at 18:43
  • Hi!

    Thanks Herbert for adding the pic!

    • and cmhughes I saw these examples and I wanted to use the intersection thing. I guess this http://tex.stackexchange.com/questions/25928/how-to-draw-tangent-line-of-an-arbitrary-point-on-a-path-in-tikz best describes what I want but I was not able to modify the code as I want; how do you define the tangent to be on the intersection?

    Is there any way to say tangent = intersection?

    – Gine Oct 01 '12 at 09:32
  • I have added the new piece of code above! (...how can I add a comment of more than 600 characters? :-) sorry...) – Gine Oct 01 '12 at 09:39
  • @Gine Adding the code to the question is the right thing to do. – egreg Oct 01 '12 at 10:35
  • 1
    Have a Look at http://tex.stackexchange.com/questions/60392/generating-dozens-of-graphs – Uwe Ziegenhagen Oct 02 '12 at 01:25

2 Answers2

3

You just have to get 2 points around the target point, as close as possible, and make a straight line between then. At that moment it will be a very short line, but then you use the undocumented tikz options shorten > and shorten < with negative values, which means you are lengthening instead shortening the segments.

enter image description here

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{arrows, intersections}

\begin{document}

    \begin{tikzpicture}
        [ 
            extended line/.style={shorten >=-#1,shorten <=-3cm}
            , extended line/.default=1cm
        ]

        \clip (-2, -1) rectangle (7,8);

        \draw [very thick, <->, >=stealth', line join=miter]
            (6,0) node (xline)[right] {$x_i$} -|
            (0,7) node (yline) [above] {$y_i$}
        ;

        \draw [blue, ultra thick, name path = my parabola] (5,1) parabola (1,7);
        \draw [name path = my reference] (2,0) -- (2,5);

        \draw [dotted, name path = line 1] (4   , 0) -- (4   , 5);
        \draw [dotted, name path = line 2] (3   , 0) -- (3   , 5);
        \draw [dotted, name path = line 3] (2.01, 0) -- (2.01, 5);


        \fill [name intersections = {of = my parabola and my reference, name = my dot}];

        \fill [name intersections = {of = my parabola and line 1, name = i1}];
        \fill [name intersections = {of = my parabola and line 2, name = i2}];
        \fill [name intersections = {of = my parabola and line 3, name = i3}];

        \fill [red]    (i1-1) circle (1.1pt);
        \fill [orange] (i2-1) circle (1.1pt);
        \fill [black]  (i3-1) circle (1.1pt);

        \draw [red   , extended line             ] (my dot-1) -- (i1-1);
        \draw [orange, extended line = 2cm       ] (my dot-1) -- (i2-1);
        \draw [black , extended line = 4cm, thick] (my dot-1) -- (i3-1);

    \end{tikzpicture}
\end{document}
tcpaiva
  • 2,574
1

Using tzplot:

enter image description here

\documentclass{standalone}

\usepackage{tzplot}

\begin{document}

\begin{tikzpicture} \tzaxes(6,6){$x_i$}{$y_i$} \tzparabola[blue,thick]"line 1"(4,1)(0,3) \tzparabola[blue,thick]"line 2"(4,2)(0,4) \tzparabola[blue,thick]"line 3"(4,3)(0,5) \tzvfnat[dashed]"line 4"{1}[0:5] \tzvfnat[dashed]"line 5"{3}[0:5] % intersection \tzXpoint*[red]{line 1}{line 4}(X) % tangent \tztangentat[blue]{line 1}{1}[0:2] % tangent: more \tztangentat[red]{line 3}{1}[0:2] \tztangentat[red]{line 2}{3}(0.3,0.2)[2:5] \end{tikzpicture}

\end{document}

I. Cho
  • 2,985