5

I'm trying to draw tangent lines to a rotated ellipse at a small interval, but I'm not sure what the best way to do this. I could just get the slopes from Wolfram Alpha, but I'd rather not hardcode the lines in.

My code:

\documentclass [10pt] {article}
\usepackage{pgfplots}
\usetikzlibrary{intersections, calc}
\usepackage{tikz}
\begin{document}
\begin{center}
\begin{tikzpicture}[scale=0.75]
    \draw[step=1cm,gray,very thin,dashed] (-2.9,-2.9) grid (2.9,2.9);
    \draw[rotate around={45:(0,0)}][thick] (0,0) ellipse (2.449cm and 1.414cm);
    \draw[thick,black,<->](0,-2.9)--(0,2.9);
    \draw[thick,black,<->](-2.9,0)--(2.9,0);
\end{tikzpicture}
\end{center}
\end{document}

So right now it's just a regular ellipse:

tilted ellipse

but I want something similar to this:

Tilted ellipse with drawn tangent lines

Although with a lot more lines, at many more points along the ellipse. How can I go about doing this?

Thruston
  • 42,268

2 Answers2

5

In Metapost, the direction t of p syntax is useful for drawing tangents. I expect the TikZ-fans can show you the equivalent for TikZ.

enter image description here

prologues := 3;
outputtemplate := "%j%c.eps";

beginfig(1);

u = 1cm;
path xx, yy, ee;
xx = (left -- right) scaled 3u;
yy = xx rotated 90;

drawdblarrow xx;
drawdblarrow yy;

ee = fullcircle xscaled 4.828u yscaled 2.828u rotated 45;

for t = 0 step 1/4 until 8:
  draw (left--right) scaled 1.5 u 
                     rotated angle direction t of ee 
                     shifted point t of ee 
                     withcolor .67 blue;
endfor

draw ee withcolor .67 red;

endfig;
end.

You also need to know that a fullcircle path (and hence an ellipse) has 8 points.

Thruston
  • 42,268
3

Something like this?

tangy

This uses a new decoration, tangy as a postaction after the main path is drawn:

\documentclass[border=10pt,tikz]{standalone}
\usetikzlibrary{decorations}
\pgfdeclaredecoration{tangy}{initial}{
  \state{initial}[width=10pt]
  {
    \pgfpathmoveto{\pgfpoint{25pt}{0}}
    \pgfpathlineto{\pgfpoint{-25pt}{0}}
    \pgfpathmoveto{\pgfpoint{+10pt}{0}}
  }
  \state{final}
  {
    \pgfpathmoveto{\pgfpointdecoratedpathlast}
  }
}
\begin{document}
\begin{tikzpicture}[scale=0.75]
    \draw [step=1cm,gray, very thin, dashed] (-2.9,-2.9) grid (2.9,2.9);
    \draw [rotate around={45:(0,0)}, thick, postaction={decorate, draw=red, thin, decoration={tangy}}] (0,0) ellipse (2.449cm and 1.414cm);
    \draw [thick, black, <->] (0,-2.9)--(0,2.9);
    \draw [thick, black, <->] (-2.9,0)--(2.9,0);
\end{tikzpicture}

This uses the fact that, when declaring a decoration, TikZ transforms the coordinate system so that the x-axis is at a tangent to the current path.

cfr
  • 198,882
  • Thanks, this is what I was looking for. Is there any documentation I can read for this? Can't seem to find anything with "LaTeX tangy" or "tex tangy" or any other combination. – Emilio Garcia Oct 17 '15 at 23:27
  • @EmilioGarcia That's because I made tangy up ;). \pgfdeclaredecoration{tangy}{}{} is creating a new decoration. The documentation for this is in the TeX manual. I actually found it by searching the manual for tangent using my PDF viewer's find facility. See section 98 'Decorations' on page 996 of the current manual. – cfr Oct 17 '15 at 23:44
  • Awesome, thanks! I was able to understand your code with the manual, didn't realize what a cool feature this is. Thanks again. – Emilio Garcia Oct 18 '15 at 01:21
  • @EmilioGarcia You're welcome. I've actually never made a decoration before (only used them), but when I searched for tangent it sounded as if it should work pretty easily - and happily it seemed to do so! – cfr Oct 18 '15 at 01:24
  • @cfr tikz manual? – Chris Chudzicki Oct 18 '15 at 01:51
  • @mrc Oops. Yes. Thank you for pointing that out. Definitely TikZ manual not TeX manual. I guess the OP must have worked it out because they do not seem as confused as I would have expected otherwise. Too bad you can't correct comments. Damn. – cfr Oct 18 '15 at 02:11