# Tikz: Emphasizing part of a drawn path

How can I emphasize the counter clockwise trajectory on ellipse ecc2768 and the clockwise trajectory on ellipse ecc6789?

Is there a command that will follow the ellipses from P1 to P2?

  \documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections, calc, arrows, decorations.markings, backgrounds}
\tikzset{
invclip/.style={
clip,
insert path={
(-16383.99999pt,-16383.99999pt) rectangle
(16383.99999pt,16383.99999pt)
}
}
}
\begin{document}
\begin{tikzpicture}[scale = 1.75,
every label/.append style = {font = \small},
dot/.style = {outer sep = +0pt, inner sep = +0pt,
shape = circle, draw = black, label = {#1}},
dot/.default =,
small dot/.style = {minimum size = 2.5pt, dot = {#1}},
small dot/.default =,
big dot/.style = {minimum size = 5pt, dot = {#1}},
big dot/.default =,
line join = round, line cap = round, >=triangle 45
]
\pgfmathsetmacro{\e}{0.2768}
\pgfmathsetmacro{\etilde}{0.6789}
\pgfmathsetmacro{\a}{1.36}
\pgfmathsetmacro{\b}{\a * sqrt(1 - \e^2)}
\pgfmathsetmacro{\btilde}{\a * sqrt(1 - (\etilde)^2)}
\pgfmathsetmacro{\c}{sqrt(\a^2 - \b^2)}
\pgfmathsetmacro{\ctilde}{sqrt(\a^2 - (\btilde)^2)}
\pgfmathsetmacro{\angle}{88.23}

\node[scale = .75, fill = orange, big dot = {below: $$F$$}] (F)
at (0, 0) {};

\draw[red, name path = r2] (0, 0) circle (1.523679cm);
\draw[blue, name path = r1] (0, 0) circle (1cm);

\begin{pgfinterruptboundingbox}
\begin{pgfonlayer}{background}
\begin{scope}[decoration = {markings,
mark = at position 0.7 with {\arrow{<}}
}]
\path[invclip] (0, 0) -- ($(0,0)!100cm!(P1)$) -- (0cm, 100cm) --
($(0,0)!100cm!(P2)$) -- (0, 0);
\draw[name path global = ecc2768, postaction = decorate] (-\c, 0)
\end{scope}
\end{pgfonlayer}
\end{pgfinterruptboundingbox}

\draw[name intersections = {of = ecc2768 and r1}] (F) -- (intersection-1)
coordinate (P1) node[fill, big dot = {right: $$P_1$$}, minimum size = 3pt]
{};

\draw[name intersections = {of = ecc2768 and r2}] (F) -- (intersection-1)
coordinate (P2) node[fill, big dot = {left, above = 2pt: $$P_2$$},
minimum size = 3pt] {};

\path [name path global = ecc6789unrotated] (\ctilde, 0) ellipse
(\a cm and \btilde cm);
\draw [name intersections = {of = r1 and ecc6789unrotated}]
(intersection-2)
let
\p0 = (F),
\p1 = (P1),
\p2 = (intersection-2),
\n1 = {atan2(\x1 - \x0, \y1 - \y0)},
\n2 = {atan2(\x2 - \x0, \y2 - \y0)},
\n3 = {\n1 - \n2}
in
\pgfextra{\xdef\myangle{\n3}}
[rotate = \n3, name path global = ecc6789rotated] (\ctilde, 0) ellipse
(\a cm and \btilde cm);

\begin{pgfinterruptboundingbox}
\begin{pgfonlayer}{background}
\path[clip] (0, 0) -- ($(0,0)!100cm!(P1)$) -- (0cm, 100cm) --
($(0,0)!100cm!(P2)$) -- (0, 0);
\draw [dashed, cyan] (-\c, 0) ellipse [x radius = \a cm,
\end{pgfonlayer}
\end{pgfinterruptboundingbox}

\end{tikzpicture}
\end{document}


This code with the invclip is causing the following errors and no pdf output.

ERROR: Dimension too large.

--- TeX said --- <recently read>

\pgf@x l.2729 \path[invclip] ( 0, 0) -- ($(0,0)!100cm!(P1)$) -- (0cm, 100c...

--- HELP --- From the .log file...

I can't work with sizes bigger than about 19 feet. Continue and I'll use the largest value I can.


• The example doesn't compile for me (missing libraries). In general, it's preferred to keep example code minimal, by removing everything that's not directly related to the current question. That way, it's much easier to understand the code, and to give general solutions that will also be useful to people other than the original asker. – Jake Jun 18 '13 at 18:17
• I agree here with @Jake (though I added the missing libraries), this example is getting really big. I can't even find the draw command which draws the ellipse that goes through P1 and P2. In general, you should be able say \draw (P1) arc [x radius=<xr>, y radius=<yr>, start angle=<ang1>, end angle=<ang2>]; where <xr> and <yr> are the radii from the ellipse and <ang1> and <ang2> are the angles from (P1)-(M) and (P2)-(M) where (M) is the center point of the ellipse. – Qrrbrbirlbel Jun 18 '13 at 18:23
• @Jake I removed more of the code. – dustin Jun 18 '13 at 18:24
• @Qrrbrbirlbel I removed more of the code. What if we don't know the angle location of P1 and P2? – dustin Jun 18 '13 at 18:25

An alternative to Qrrbrbirlbels's approach of calculating the angles is to use a large clipping path and then drawing the ellipse again, possibly using layers to place it behind the original ellipse.

Here's an example of highlighting a segment of an ellipse between two arbitrary points (we assume we don't know the angles of the points along the ellipse).

The approach can be combined with Paul Gaborit's invclip to invert the clipping region.

  \documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc, backgrounds}
\tikzset{
invclip/.style={
clip,
insert path={
(-16383.99999pt,-16383.99999pt) rectangle (16383.99999pt,16383.99999pt)
}
}
}
\begin{document}
\begin{tikzpicture}
\fill (27:4cm and 2cm) circle [radius=2pt] coordinate (P1);
\fill (137:4cm and 2cm) circle [radius=2pt] coordinate (P2);

\begin{pgfinterruptboundingbox} % To prevent the clipping path from making our picture larger
\begin{pgfonlayer}{background}
\begin{scope} % to limit the clip
\path [clip] (0,0) -- ($(0,0)!100cm!(P1)$) -- (0cm,100cm) --  ($(0,0)!100cm!(P2)$) -- (0,0);
\end{scope}

\begin{scope} % to limit the clip
\path [invclip] (0,0) -- ($(0,0)!100cm!(P1)$) -- (0cm,100cm) --  ($(0,0)!100cm!(P2)$) -- (0,0);
\end{scope}
\end{pgfonlayer}
\end{pgfinterruptboundingbox}
\end{tikzpicture}
\end{document}

• @dustin: Yes, see tex.stackexchange.com/a/59168/2552 (or search for reverseclip on this site) – Jake Jun 18 '13 at 19:29
• @dustin: have you compiled it twice? Also, my solution might not work with standalone, try Paul's in that case. – Jake Jun 18 '13 at 19:51
• @dustin: I added an example using Pauls invclip (it's actually much better than my reverseclip). – Jake Jun 18 '13 at 20:21
• @dustin: Ah, yes, that happens because you have the scale=1.75 option in your example. In that case, you have to decrease the size of the rectangle in the invclip code. – Jake Jun 18 '13 at 21:47
• @dustin Use insert path={ {[reset cm] (-16383.99999pt,-16383.99999pt) rectangle (16383.99999pt,16383.99999pt)}} instead of the original insert path. Though, you will still get problems because you use P1 and P2 before they are defined or you use the path ecc2768 before it is defined. – Qrrbrbirlbel Jun 18 '13 at 21:51

After specifying the ellipse’s center point as coordinate (M) in:

\draw[name path global = ecc2768, postaction = decorate]
(-\c, 0) coordinate (M) ellipse (\a cm and \b cm);


We can re-draw the arc with

\draw[green!50!black, thick] let \p1=($(P1)-(M)$),
\p2=($(P2)-(M)$) in
start angle={atan2(\x1, \y1)},
end angle={atan2(\x2, \y2)}
];


There seem to be some small imprecision between that arc and the ellipse, this happens also when drawing from the other point:

\draw[yellow!50!black, thick] let \p1=($(P1)-(M)$),
\p2=($(P2)-(M)$) in
start angle={atan2(\x2, \y2)},
end angle={atan2(\x1, \y1)}
];


This may or may not be corrected manually.

## Code

\documentclass[border=5mm,convert=false]{standalone}
\usepackage{tikz}
\usetikzlibrary{intersections, calc, arrows, decorations.markings}
\begin{document}
\begin{tikzpicture}[scale = 1.75,
every label/.append style = {font = \small},
dot/.style = {outer sep = +0pt, inner sep = +0pt,
shape = circle, draw = black, label = {#1}},
dot/.default =,
small dot/.style = {minimum size = 2.5pt, dot = {#1}},
small dot/.default =,
big dot/.style = {minimum size = 5pt, dot = {#1}},
big dot/.default =,
line join = round, line cap = round, >=triangle 45
]
\pgfmathsetmacro{\e}{0.2768}
\pgfmathsetmacro{\etilde}{0.6789}
\pgfmathsetmacro{\rone}{1}
\pgfmathsetmacro{\rtwo}{1.524}
\pgfmathsetmacro{\deltanu}{107}
\pgfmathsetmacro{\a}{1.36}
\pgfmathsetmacro{\am}{1.1442}
\pgfmathsetmacro{\s}{2 * \am}
\pgfmathsetmacro{\cord}{2 * \s - \rone - \rtwo}
\pgfmathsetmacro{\b}{\a * sqrt(1 - \e^2)}
\pgfmathsetmacro{\btilde}{\a * sqrt(1 - (\etilde)^2)}
\pgfmathsetmacro{\c}{sqrt(\a^2 - \b^2)}
\pgfmathsetmacro{\ctilde}{sqrt(\a^2 - (\btilde)^2)}
\pgfmathsetmacro{\angle}{88.23}

\draw[dashed, rotate = \angle] (-\a + \ctilde, 0) -- (\a + \ctilde, 0);
\draw[dashed] (-\a - \c, 0) -- (\a - \c, 0);
\node[scale = .75, fill = orange, big dot = {below: $$F$$}] (F)
at (0, 0) {};
\node[scale = .75, fill = white, big dot = {below: $$F^*$$}] (FS)
at (-2 * \c cm, 0) {};
\draw[red, name path = r2] (0, 0) circle (1.523679cm);
\draw[blue, name path = r1] (0, 0) circle (1cm);
\begin{scope}[decoration = {markings,
mark = at position 0.15 with {\arrow{>}},
mark = at position 0.7 with {\arrow{<}}
}]
\draw[name path global = ecc2768, postaction = decorate] (-\c, 0) coordinate (M) ellipse (\a cm and \b cm);
\end{scope}
\draw[name intersections = {of = ecc2768 and r1}] (F) -- (intersection-1)
coordinate (P1) node[fill, big dot = {right: $$P_1$$}, minimum size = 3pt]
{};
\draw[name intersections = {of = ecc2768 and r2}] (F) -- (intersection-1)
coordinate (P2) node[fill, big dot = {left, above = 2pt: $$P_2$$},
minimum size = 3pt] {};

\draw[green!50!black, thick] let \p1=($(P1)-(M)$),
\p2=($(P2)-(M)$) in
start angle={atan2(\x1, \y1)},
end angle={atan2(\x2, \y2)}
];
\draw[yellow!50!black, thick] let \p1=($(P1)-(M)$),
\p2=($(P2)-(M)$) in

• Since there is an there is a precision error, would it be possible to have the original ellipse dash from P1 to P2 then without drawing over it? – dustin Jun 18 '13 at 18:43
• If I remember correctly \pgfprecomputedarc is better for precision but that was some time ago. – percusse Jun 18 '13 at 18:53
• @dustin Alternatively, you could simply re-draw the ellipse but clipping against an area from P1 to P2. – Qrrbrbirlbel Jun 18 '13 at 19:08