In the classical arc
command in TikZ, we specify an endpoint of the arc, followed by the initial and final angles, and finally the radius.
I would like to create a macro (if it doesn't already exist) that instead of specifying the angles and radius, specifies two distances, one horizontal and one vertical as shown below :
Note that this command is less powerful than the usual arc
command as it
only draws arcs that are symmetric with respect to some vertical axis.
The conversion formulas are as follows : the radius is $\frac{a^2+b^2}{2b}$
and the initial angle is $cos^{-1}(\frac{2ab}{a^2+b^2})$.
Here is my failed attempt to implement this with tikzset
(in the
test file below, the two tikzpictures should be identical) :
\documentclass{article}
\usepackage{tikz}
\usepackage{calc}
\begin{document}
\tikzset{
afro/.style args={#1:#2}{
insert path={ arc(acos((2*#1*#2)/(#1*#1+#2*#2)):180-acos((2*#1*#2)/(#1*#1+#2*#2)):((#1*#1+#2*#2)/(2*#1*#2)))}
}
}
\begin{tikzpicture}
\draw[green] (0,0) arc (37:143:2.5cm);
\draw (0,0) node {$O$};
\end{tikzpicture}
\begin{tikzpicture}
\draw[red] (0,0) afro (2cm:1cm);
\draw (0,0) node {$O$};
\end{tikzpicture}
\end{document}
Perhaps I should use pgfkeys ? Any help appreciated.
afro
style: 1. It is a style, it need to be applied inside[
and]
; 2. You declare#1:#2
but use(#1:#2)
; 3. You did not protect the parenthesis. You will need to doarc({acos(…)}:{180-acos(…)}:{((…))})
and\draw[red] (0,0) [afro=2cm:1cm]
.