What is the best and simplest way to denote an angle, with an arc and a label telling its name? I wish to be able to control (obviously) the vertices on which the angle lays, the name of the angle and also control the radius of the little arc and whether it should fill the whole part-of-a-circle shape in color.
[Tex/LaTex] Best way to denote an angle in TikZ
tikz-pgf
Related Solutions
Only part of what was required. But it also shows how a key with the required syntax could be programmed:
\documentclass[tikz,border=5]{standalone}
\tikzset{%
insert arc/.style args={#1:#2:#3and#4 with center #5}{
insert path={
\pgfextra{%
\pgfpointxy{#3}{#4}%
\pgfgetlastxy\arcrx\arcry%
\pgfcoordinate{#5}{%
\pgfpoint{\csname tikz@lastx\endcsname+\arcrx*cos(#1+180)}%
{\csname tikz@lasty\endcsname+\arcry*sin(#1+180)}}
}
arc (#1:#2:#3 and #4)
}
}
}
\begin{document}
\begin{tikzpicture}[rotate=40]
\draw [very thick] (0,0) [insert arc={-25:45:3 and 2 with center X}];
\draw [dashed, red] (X) ellipse [x radius=3, y radius=2];
\end{tikzpicture}
\end{document}
And a slightly more comprehensive example:
\begin{tikzpicture}
\draw [very thick] (0,0) -- (0,1)
[insert arc={270:135:3 and 2 with center X}] -- (-4,4)
[insert arc={ 10:-90:1 and 3 with center Y}]
[insert arc={180:360:4 and 2 with center Z}] -- cycle;
\draw [dashed, red] (X) ellipse [x radius=3, y radius=2];
\draw [dashed, green] (Y) ellipse [x radius=1, y radius=3];
\draw [dashed, blue] (Z) ellipse [x radius=4, y radius=2];
\end{tikzpicture}
A solution which allows to draw intersection segments
of any two intersections is available as tikz library fillbetween
.
This library works as general purpose tikz
library, but it is shipped with pgfplots
and you need to load pgfplots
in order to make it work:
\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{fillbetween}
\begin{document}
\begin{tikzpicture}
\draw [name path=red,red] (120:1.06) circle (1.9);
%\draw [name path=yellow,yellow] (0:1.06) circle (2.12);
\draw [name path=green,green!50!black] (0:0.77) circle (2.41);
\draw [name path=blue,blue] (0:0) circle (1.06);
% substitute this temp path by `\path` to make it invisible:
\draw[name path=temp1, intersection segments={of=red and blue,sequence=L1}];
\draw[red,-stealth,ultra thick, intersection segments={of=temp1 and green,sequence=L3}];
\end{tikzpicture}
\end{document}
The key intersection segments
is described in all detail in the pgfplots
reference manual section "5.6.6 Intersection Segment Recombination"; the key idea in this case is to
create a temporary path
temp1
which is the first intersection segment ofred and blue
, more precisely, it is the first intersection segment in theL
eft argument inred and blue
:red
. This path is drawn as thin black path. Substitute its\draw
statement by\path
to make it invisible.Compute the desired
intersection segment
by intersectingtemp1
andgreen
and use the correct intersection segment. By trial and error I figured that it is the third segment of pathtemp1
which is written asL3
(L
= left argument intemp1 and green
and3
means third segment of that path).
The argument involves some trial and error because fillbetween
is unaware of the fact that end and startpoint are connected -- and we as end users do not see start and end point.
Note that you can connect these path segments with other paths. If such an intersection segment
should be the continuation of another path, use --
as before the first argument in sequence. This allows to fill paths segments:
\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{fillbetween}
\begin{document}
\begin{tikzpicture}
\draw [name path=red,red] (120:1.06) circle (1.9);
%\draw [name path=yellow,yellow] (0:1.06) circle (2.12);
\draw [name path=green,green!50!black] (0:0.77) circle (2.41);
\draw [name path=blue,blue] (0:0) circle (1.06);
% substitute this temp path by `\path` to make it invisible:
\draw[name path=temp1, intersection segments={of=red and blue,sequence=L1}];
\draw[red,fill=blue,-stealth,ultra thick, intersection segments={of=temp1 and green,sequence=L3}]
[intersection segments={of=temp1 and green, sequence={--R2}}]
;
\end{tikzpicture}
\end{document}
Best Answer
I just have a look to this question and related ones but I don't see anywhere my solution to mark an angle when you don't know its measure (maybe I haven't read all the post about the topic...).
So here it is:
I draw a full circle and I hide the bad part of it by clipping with a path built with the three points which define the angle. It seems so easy that it might be a bad way to do it but it works pretty well. Here I put manually the angle measure to place
\theta
but it could be automated surely.Please, feel free to comment it if you think there are some situations where it doesn't work!