# TikZ: Drawing an arc between two points

From my post TikZ: Drawing an ellipse through two points, I am trying to replicate the process for a different arc put it isn't working as anticipated. The problem is I don't understand the code below that well.

\draw[postaction = decorate] let
\p0 = ($(B) - (F)$),
\p1 = ($(A) - (B)$)
in (B|-A) ++(\x1, 0) arc(45:135:\x1 and \y0);


What is (B|-A) doing? Why the subtraction of the points.

I am trying to connect (A) to (B).

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections, decorations.markings, calc, arrows}
\begin{document}
\begin{tikzpicture}[line join = round, line cap = round, >=triangle 45,
every label/.append style = {font = \scriptsize},
dot/.style = {inner sep = +0pt, shape = circle,
draw = black, label = {#1}},
small dot/.style = {minimum size = .05cm, dot = {#1}},
big dot/.style = {minimum size = .1cm, dot = {#1}},
]
\pgfmathsetmacro{\as}{3}
\pgfmathsetmacro{\bs}{2.25}
\pgfmathsetmacro{\c}{sqrt(\as^2 - \bs^2)}
\pgfmathsetmacro{\al}{3.75}
\pgfmathsetmacro{\bl}{sqrt(\al^2 - \c^2)}

\coordinate (O) at (0, 0);

\node[fill = black, big dot = {below left: $$F$$}] (F) at (\c, 0) {};

\path[name path = line1] (\c, 0) -- ++(45:{\as} and \bs);
\path[name path = line2] (\c, 0) -- ++(135:5cm and 5cm);

\path[name path = ell1] (O) ellipse
(\as cm and \bs cm);

\path[name path = ell2] (O) ellipse
(\al cm and \bl cm);

\path[name intersections = {of = line1 and ell1, by = P1}];
\node[fill = black, big dot = {above right: $$A$$}] (A) at (P1) {};

\path[name intersections = {of = line2 and ell2, by = P2}];
\node[fill = black, big dot = {above right: $$B$$}] (B) at (P2) {};

\draw[blue] (F) -- (A);
\draw[red] (F) -- (B) node[scale = .75, fill = white, inner sep = 0cm,
pos = .5] {$$r_B$$};

\begin{scope}[decoration = {markings,
mark = at position 0.5 with {\arrow{>}},
} ]
\draw[postaction = decorate] let
\p0 = ($(B) - (F)$),
\p1 = ($(A) - (B)$)
in (B|-A) ++(\x1, 0) arc(45:135:\x1 and \y0);
\end{scope}
\end{tikzpicture}
\end{document}


Edit 2:

Following Qrrbrbirlbel solutions, I get the correct figure but I am receiving an error and I can't figure it out:

ERROR: Undefined control sequence.

--- TeX said ---
\tikz@intersect@namedpaths ...name@f'Circle-\solA
\endcsname {\pgfsyssoftpat...
l.108   {$$\nu_B$$};

--- HELP ---
TeX encountered an unknown command name. You probably misspelled the
name. If this message occurs when a LaTeX command is being processed,
the command is probably in the wrong place---for example, the error
can be produced by an \item command that's not inside a list-making
environment. The error can also be caused by a missing \documentclass
command.


The code I am using is:

\documentclass[tikz]{standalone}
\usetikzlibrary{intersections, decorations.markings, calc, arrows, backgrounds}
\begin{document}
\tikzset{circle with radius/.style = {shape = circle, inner sep = 0pt,
outer sep = 0pt, minimum size = {2 * (#1)}}}
\begin{tikzpicture}[line join = round, line cap = round, >=triangle 45,
every label/.append style = {font = \scriptsize},
dot/.style = {inner sep = +0pt, shape = circle,
draw = black, label = {#1}},
small dot/.style = {minimum size = .05cm, dot = {#1}},
big dot/.style = {minimum size = .1cm, dot = {#1}},
]
\pgfmathsetmacro{\as}{3}
\pgfmathsetmacro{\bs}{2.25}
\pgfmathsetmacro{\c}{sqrt(\as^2 - \bs^2)}
\pgfmathsetmacro{\al}{3.75}
\pgfmathsetmacro{\bl}{2.9}
\pgfmathsetmacro{\cl}{sqrt(\al^2 - \bl^2)}
\pgfmathsetmacro{\xs}{abs(\c - \cl)}

\coordinate (O) at (0, 0);

\node[fill = black, big dot = {below left: $$F$$}] (F) at (\c, 0) {};

\path[name path global = line1] (\c, 0) -- ++(60:{\as} and \bs);
\path[name path global = line2] (\c, 0) -- ++(150:6cm);

\begin{scope}[decoration = {markings,
mark = at position 0.25 with {\arrow{>}},
mark = at position 0.375 with {\node[draw, shape = circle,
inner sep = .08cm, fill = white, scale = .75] {$$1$$};},
mark = at position 0.75 with {\arrow{>}},
} ]
\draw[postaction = decorate, name path global = ell1, blue] (O) ellipse
(\as cm and \bs cm);
\end{scope}

\begin{scope}[decoration = {markings,
mark = at position 0.25 with {\arrow{>}},
mark = at position 0.45 with {\node[draw, shape = circle,
inner sep = .08cm, fill = white, scale = .75] {$$2$$};},
mark = at position 0.75 with {\arrow{>}},
},
on background layer]
\draw[postaction = decorate, name path global = ell2, red] (-\xs, 0)
ellipse (\al cm and \bl cm);
\end{scope}

\path[name intersections = {of = line1 and ell1, by = P1}];
\node[fill = black, big dot = {right: $$A$$}] (A) at (P1) {};

\path[name intersections = {of = line2 and ell2, by = P2}];
\node[fill = black, big dot = {above: $$B$$}] (B) at (P2) {};

\draw[blue] (F) -- (A);
\draw[red] (F) -- (B) node[scale = .75, fill = white, inner sep = 0cm,
pos = .5] {$$r_B$$};

\begin{scope}[on background layer]
\draw[dashed, -latex] ($(-\al , 0) - (1, 0)$) -- ($(\al, 0) + (.5, 0)$)
coordinate (P3);
\draw[dashed, -latex] ($(F) - (0, 3)$) -- ($(F) + (0, 3)$);
\end{scope}

\begin{scope}[declare function = {doubleA = 7cm;}]
\begin{pgfinterruptboundingbox}
\path let
\p1 = ($(A) - (F)$),
\p2 = ($(B) - (F)$),
\n1 = {veclen(\x1, \y1)},
\n2 = {veclen(\x2, \y2)}
in
(A) node[name path global = aCircle, circle with radius = doubleA-\n1] {}
(B) node[name path global = bCircle, circle with radius = doubleA-\n2] {}
(F) node[name path global = fCircle, circle with radius = .5 * doubleA]
{};

\tikzset{name intersections = {of = aCircle and bCircle, name = F',
}}
\foreach \solA in {1, 2} {
\path ($(F)!.5!(F'-\solA)$) coordinate (C'-\solA)
($(C'-\solA)!doubleA/2!(F)$) coordinate (xDir-\solA)
(F'-\solA) node[name path global = f'Circle-\solA,
circle with radius = .5 * doubleA] {};
}                         %!?
\foreach \solA in {1, 2} { %!?
\path[name intersections = {of = fCircle and f'Circle-\solA,
by = {yDir-\solA}}]
($(xDir-\solA)-(C'-\solA)$) coordinate (xDir'-\solA)
($(yDir-\solA)-(C'-\solA)$) coordinate (yDir'-\solA)
;
}
\end{pgfinterruptboundingbox}
\foreach \solA in {1, 2}
\draw[x = (xDir'-\solA), y = (yDir'-\solA)] (C'-\solA) circle [radius = 1];
\end{scope}

\draw[on background layer, red] let
\p0 = (F),
\p1 = (B),
\p2 = (P3),
\n1 = {atan2(\x1 - \x0, \y1 - \y0)},
\n2 = {atan2(\x2 - \x0, \y2 - \y0)},
\n3 = {.75cm},
\n4 = {(\n2 + \n1) / 2}
in (F) +(\n1:\n3) arc[radius = \n3, start angle = \n1, end angle = \n2]
node[font = \tiny, fill = white, inner sep = 0cm] at ([shift = (F)] \n4:\n3)
{$$\nu_B$$};

\draw[blue] let
\p0 = (F),
\p1 = (A),
\p2 = (P3),
\n1 = {atan2(\x1 - \x0, \y1 - \y0)},
\n2 = {atan2(\x2 - \x0, \y2 - \y0)},
\n3 = {.5cm},
\n4 = {(\n2 + \n1) / 2}
in (F) +(\n1:\n3) arc[radius = \n3, start angle = \n1, end angle = \n2]
node[font = \tiny, fill = white, inner sep = 0cm] at
([shift = (F)] \n4:.75cm) {$$\nu_A$$};
\end{tikzpicture}
\end{document}


-
Do you want to draw an arc of circle or ellipse? To draw and arc of circle you should determine the center of the circle since two points don't well define a unique circle. –  Sigur Jul 6 '13 at 20:57
I think it would be really helpful if you could reduce your examples a lot more before posting them. At the moment, trying to answer this question requires wading through a lot of code that isn't directly concerned with the problem at hand. That's not very fun, and it makes the questions very localised (they're more like "Please fix my drawing" rather than "How can I do X?"). Questions on this site should be written with other people in mind that might have similar problems. –  Jake Jul 6 '13 at 21:08
So you should know the axis or the focus. –  Sigur Jul 6 '13 at 22:51
But there are many ellipses with focus at F and containing A and B. You can not determine only one if you don't know the other focus. –  Sigur Jul 6 '13 at 22:55
Is this helpful? tex.stackexchange.com/questions/103945/… –  karathan Jul 6 '13 at 23:27
show 1 more comment

Here is one idea to get an ellipse with the focal point F which goes throug points A and B. I took the liberty to assume
2a = 7 cm
where a is the length of the long axis of the ellipse.

Given the information I remember about ellipses, this is also the sum of the distances between one point on the ellipse and both focal points respectively. We can use this to get two possible focal points F’1 and F’2.

To do this in TikZ I use calc’s let … in syntax to find the length between the given focal point and the points, then I place nodes around those points with the remainder of those 2a. The intersection cs helps then to find the focal points. The center of the ellipsoid arc is then simply in the middle of those two focal points, we found C ’.

From this center we can find the x, the point where the big axis points to (and also the x axis of that rotates ellipse); again, calc to the rescue: ($(C')!doubleA/2!(F)$).

Now, we could do some funny calculation with a and the linear eccentricity to find b, the length of the small axis but this is math PGF can’t do without help. But if I recollect correctly the coordinate y where the small axis points to is equal distances away from both focal points; namely a. So, let’s draw circles around F and F’ and use the intersection cs again.

The coordinates x and y are defined in the TikZ solution below with xDir and yDir. We can use them to install a local coordinate system that has exactly the axes from the ellipse as axes. A circle with radius 1 is then the ellipse we search (or the full arc on which you look for an part).

As the circular auxiliary nodes do change the bounding box I put these calculations in a pgfinterruptboundingbox environment and save the vectors in xDir' and yDir'.

A ellipse can then be simply drawn by

\draw[x=(xDir'),y=(yDir')] (C') circle [radius=1];


I have used the intersection cs here, because it is much easier to maintain (and you can do all on one path. The same can achieved with the intersections library, too.

For some reason though, TikZ messes up the placement of the second center (C'-2) when you want to name a node path and find an intersection of it in the same loop (comment the with !? marked lines out). Dividing this up in two loops will however result in the correct outcome:

### Code (intersections library)

\begin{scope}[declare function={doubleA=7cm;}]
\begin{pgfinterruptboundingbox}
\path let \p1=($(A)-(F)$), \p2=($(B)-(F)$), \n1={veclen(\x1,\y1)},\n2={veclen(\x2,\y2)} in
(A) node[name path=aCircle, circle with radius=doubleA-\n1] {}
(B) node[name path=bCircle, circle with radius=doubleA-\n2] {}
(F) node[name path=fCircle, circle with radius=.5*doubleA]  {};

\tikzset{name intersections={of=aCircle and bCircle,name=F',by={[big dot=below:$F'_1$],[big dot=below:$F'_2$]}}}
\foreach \solA in {1,2} {
\path ($(F)!.5!(F'-\solA)$) coordinate[big dot=$C'_\solA$] (C'-\solA)
($(C'-\solA)!doubleA/2!(F)$) coordinate[big dot=right:$x_\solA$] (xDir-\solA)
(F'-\solA) node[name path global=f'Circle-\solA, circle with radius=.5*doubleA] {};
}                         %!?
\foreach \solA in {1,2} { %!?
\path[name intersections={of=fCircle and f'Circle-\solA,by={[big dot=above right:$y_\solA$]yDir-\solA}}]
($(xDir-\solA)-(C'-\solA)$) coordinate (xDir'-\solA)
($(yDir-\solA)-(C'-\solA)$) coordinate (yDir'-\solA)
;
}
\end{pgfinterruptboundingbox}
\foreach \solA in {1,2}
\end{scope}


## Code

\documentclass[tikz]{standalone}
\usetikzlibrary{intersections, decorations.markings, calc, arrows}
\tikzset{circle with radius/.style={shape=circle, inner sep=+0pt, outer sep=+0pt, minimum size={2*(#1)}}}
\begin{document}
\begin{tikzpicture}[line join = round, line cap = round, >=triangle 45,
every label/.append style = {font = \scriptsize},
dot/.style = {inner sep = +0pt, shape = circle, draw = black, label = {#1}},
small dot/.style = {minimum size = .05cm, dot = {#1}},
big dot/.style = {minimum size = .1cm, dot = {#1}},
]
\pgfmathsetmacro{\as}{3} \pgfmathsetmacro{\bs}{2.25}
\pgfmathsetmacro{\c}{sqrt(\as^2 - \bs^2)}
\pgfmathsetmacro{\al}{3.75}
\pgfmathsetmacro{\bl}{sqrt(\al^2 - \c^2)}
\coordinate (O) at (0,0); \node[fill = black, big dot = {below left: $$F$$}] (F) at (\c, 0) {};

\path[name path = line1] (\c, 0) -- ++(45:{\as} and \bs);
\path[name path = line2] (\c, 0) -- ++(135:5cm and 5cm);
\path[name path = ell1] (O) ellipse (\as cm and \bs cm);
\path[name path = ell2] (O) ellipse (\al cm and \bl cm);

\path[name intersections = {of = line1 and ell1, by = P1}];
\node[fill = black, big dot = {above right: $$A$$}] (A) at (P1) {};
\path[name intersections = {of = line2 and ell2, by = P2}];
\node[fill = black, big dot = {above right: $$B$$}] (B) at (P2) {};

\draw[blue] (F) -- (A);
\draw[red]  (F) -- (B) node[scale = .75, fill = white, inner sep = 0cm, pos = .5] {$$r_B$$};

\begin{scope}[declare function={doubleA=7cm;}]
\foreach \solA in {1,2} {
\begin{pgfinterruptboundingbox}
\path let \p1=($(A)-(F)$), \p2=($(B)-(F)$), \n1={veclen(\x1,\y1)},\n2={veclen(\x2,\y2)} in
(A) node[circle with radius=doubleA-\n1] (aCircle) {}
(B) node[circle with radius=doubleA-\n2] (bCircle) {}
(intersection cs: first node=aCircle, second node=bCircle, solution=\solA) coordinate[big dot=below:$F'_\solA$] (F')
($(F)!.5!(F')$) coordinate[big dot=$C'_\solA$] (C')% the center of the arc
($(C')!doubleA/2!(F)$) coordinate[big dot=right:$x_\solA$] (xDir)
(F) node[circle with radius=.5*doubleA] (fCircle) {}
(F') node[circle with radius=.5*doubleA] (f'Circle) {}
(intersection cs: first node=fCircle, second node=f'Circle, solution=1) coordinate[big dot=above right:$y_\solA$] (yDir)
($(xDir)-(C')$) coordinate (xDir')
($(yDir)-(C')$) coordinate (yDir')
;
\end{pgfinterruptboundingbox}
}
\end{scope}
\end{tikzpicture}
\end{document}


## Output

-
@dustin I believe it is not very accurate. I/we discovered similar inaccuracies at Tikz: placing a node at the intersection of two circles along a hyperbola before. But it shouldn’t be too hard to write the same with paths, you probably can do it entirely on one path, too. –  Qrrbrbirlbel Jul 8 '13 at 3:03
@dustin I have added the intersections library solution. There was some problems with the \foreach looping over both solutions, each loop only covering one of the solution was not a problem, but both in one loop messed up the second one. Dividing this task up on two loops though helped. A little messy but it works now. I guess, you only want one of both solutions anyway, so that won’t be a problem? –  Qrrbrbirlbel Jul 8 '13 at 21:10
@Qrrbrbirlbel I think you need name path global or something with global ( I don't remember) because \foreach works inside a local group... Well you used it already how smart of me :) –  percusse Jul 8 '13 at 21:17
@dustin Interesting, with the code from my answer it works without but your code does need name path global/.expanded = f'Circle-\solA (notice the /.expanded handler). This makes sure \solA is expanded before the path gets its name which otherwise would still have \solA in it which is not defined after the \foreach loop. –  Qrrbrbirlbel Jul 8 '13 at 23:07