I want to create a plot of the following parametric equations:

x(t)=t*sin(t), y(t)=t*cos(t)
-3pi/2 <= t <= 3pi/2

Also, I want to show the tangent line on the same chart, which is:

y-o = (-pi/2)(x-(pi/2))

I've never really played around with parametric plots and I am not particular on package. Whatever is easiest to use. Can anyone help me out on how I can do this? Thanks!


For fun, the pstricks way:

\documentclass[svgnames, x11names, border=3pt]{standalone}%
\usepackage{pst-plot, pst-math, pst-text, auto-pst-pdf}%


 \psset{arrowinset=0.12, algebraic, plotstyle=curve, plotpoints=1000}%
    \psaxes[linecolor=LightSteelBlue3, ticksize =2pt -2pt, ]{->}(0,0)(-5.5,-5)(4,5)[$x$, -120][$y$, -135]
    \uput[dl](0,0){$O $}
     \uput[d](\psPiH, 0){$ \frac{\pi}{2}$} \uput[-120](-\tsup, 0){$ -\frac{3\pi}{2}$}
     \uput[120](0,\psPi){$\pi$} \uput[-120](0,-\psPi){$-\pi$} 
    \parametricplot[linewidth=1.2pt, linecolor=IndianRed]{-\tsup}{\tsup}{\paracurve}
    \psplotTangent[linecolor=Goldenrod1, linewidth=0.4pt]{\psPiH}{6}{\paracurve}


enter image description here

| improve this answer | |
  • This one is perfect, since it sort of matches some of the other stuff I have done with pstricks. Love it. – azdatasci Oct 15 '19 at 16:52

Drawing the plot is very simple:

\draw plot[variable=\t,domain=-3*pi/2:3*pi/2,smooth,samples=51] 

where \t is the parameter. Here we use trig format=rad to switch to radians. For your convenience I added a style tangent at that attaches the tangent at a given t value. The components are just given by the t derivatives of your x(t) and y(t). The length is stored in tangent length. To get a tangent of length 2 at t=pi, say, you can write

\draw[blue,tangent length=2,tangent at=pi];

Full code:

\begin{tikzpicture}[trig format=rad,tangent at/.style={insert path={
 ({#1*sin(#1)},{#1*cos(#1)}) ++ 
 -- ++ ({(-2*#1*cos(#1)-2*sin(#1))/(2*\mylength)},
 tangent length/.initial=1]
 \draw plot[variable=\t,domain=-3*pi/2:3*pi/2,smooth,samples=51] 
 \draw[tangent at=2];
 \draw[blue,tangent length=2,tangent at=pi];
 \draw[red,tangent length=3,tangent at=-pi/2];

enter image description here

One can also attach tangents using decorations.markings but in your case the curve's parametrization is known so it might be better to do it analytically.

| improve this answer | |
  • I like this one and its flexibility to add tangent lines. I'm using pstricks for other stuff already, so the solution below is a natural implementation right now, but I'm going to keep this one in mind for future things. I like it. – azdatasci Oct 15 '19 at 16:54

An attempt with MetaPost, included in a LuaLaTeX program, using some macros of my own. The tangent is computed by MetaPost itself, no need to know its equation.


    vardef param_fcn (expr tmin, tmax, tstep)(text f_t)(text g_t) =
        save t; t := tmin;      
        (f_t, g_t)      
        forever: hide(t := t+tstep) exitif t > tmax;
            .. (f_t, g_t) 
        if t - tstep <> tmax: hide(t := tmax) .. (f_t, g_t) fi

    vardef f(expr t) = t * sin t enddef;
    vardef g(expr t) = t * cos t enddef;


        u = cm;
        tmax = -tmin = 3*pi/2; tstep = .01;
        path curve;  curve = param_fcn(tmin, tmax, tstep)(f(t))(g(t));
        draw curve scaled u withcolor red;

        s := pi/2; pair M, P, Q; 
        M = (f(s),g(s)); 
        pair tgt; tgt = unitvector(direction (s-tmin)/tstep of curve);
        P = M + 4tgt; Q = M - 4tgt; draw (P--Q) scaled u withcolor green;

        xmax = ymax = 4.5; xmin = -5; ymin = -ymax ; label.llft("$O$", origin);
        drawarrow (xmin*u,0) -- (xmax*u, 0); label.bot("$x$", (xmax*u,0));
        drawarrow (0, ymin*u) -- (0, ymax*u); label.lft("$y$", (0,ymax*u));

        for i = -3 upto 2:
            if i<>0: 
                xi := i/2*pi*u;
                draw (xi, -2bp) -- (xi, 2bp); fi

        for j = -2 upto 2:
            if j<>0: 
                yj := j/2*pi*u;
                draw (-2bp, yj) -- (2bp, yj); fi

        label.bot("$\pi$", (pi*u,0)); label.bot("$\dfrac{\pi}{2}$", (pi*u/2,0)); 
        label.bot("$\dfrac{-\pi}{2}$", (-pi/2*u,0));
        label.bot("$-\pi$", (-pi*u, 0)); label.llft("$\dfrac{-3\pi}{2}$", (-3pi/2*u,0));
        label.urt("$\pi$", (0, pi*u)); label.lrt("$-\pi$", (0, -pi*u));



enter image description here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.