I'm just trying to learn graphical packages (tikz, pgfplots..) and I would like to see how a more expert user would approach such a drawing.
-
1The tkz-euclide package might be worth a look– samcarter_is_at_topanswers.xyzCommented Oct 24 at 11:03
-
@samcarter_is_at_topanswers.xyz thank you so much! I will check it out– lucottoDACommented Oct 24 at 11:04
-
Welcome. // Tikz will do as well (tkz-euclide is built on it). // Are you sure about the orientations of the slits? Will work, but is an unusual orientation.– MS-SPOCommented Oct 24 at 11:48
-
In tikz.dev look for: A) the tutorials, B) basics: grid, draw, node, C) later tikzlibraries: arrows.neta, angle/s. Use standard latex within the nodes, e.g. for greek, like $\theta$.– MS-SPOCommented Oct 24 at 12:05
-
2@MS-SPO tysm! I wll surely give it a look. What do you mean with "slits"? (sorry, I'm italian) if you're talking about the 2 segments divided by a gap, those are antennas (at least, antennas as drawn by my professor lol) and this is a exercise about electromagnetic fields– lucottoDACommented Oct 24 at 13:52
|
Show 3 more comments
1 Answer
You need to know around 5 things about TikZ.
Then somehow like this:
\documentclass[margin=5pt, tikz]{standalone}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{backgrounds}
\usetikzlibrary{angles, quotes, babel}
\usetikzlibrary {arrows.meta, bending}
\usetikzlibrary{decorations.markings}
\definecolor{mybgcolor}{HTML}{F8F6E9}
\begin{document}
\pgfmathsetmacro\wTheta{22.5}
\pgfmathsetmacro\L{2.575}
\begin{tikzpicture}[font=\footnotesize,
>={Triangle[length=0pt 3*2.5,width=0pt 2.5]},
background rectangle/.style={draw=none, fill=mybgcolor},
show background rectangle,
]
% 1
\draw[step=0.5, help lines] (-0.2,-0.2) grid (4.2,3.2);
% 2
\draw[red, thick] (1,0.5) coordinate(A1) -- +(\wTheta:\L) coordinate(B1) ;
\draw[red, thick] (1,2) coordinate(A2) -- +(\wTheta:\L) coordinate(B2) ;
% 3
\draw[red, densely dotted] (A2) -- ($(A1)!(A2)!(B1)$) coordinate(A2s) coordinate[pos=1.35, label=center:](A2ss);
\draw[densely dotted] (A2s) -- (A2ss);
\draw[densely dotted, shorten >=-1mm] (A1) -- ($(A1)!2.25mm!-90:(B1)$) coordinate(A1s);
\draw[<->] (A1s) -- ($(A2s)!(A1s)!(A2ss)$) node[midway, below, sloped, inner sep=1.5pt]{$\Delta$};
% 4
\draw[<->] ([xshift=-6mm]A1) -- ([xshift=-6mm]A2) node[midway, right]{$d$};
% 5a
\tikzset{
pics/mypic/.style={%%
code={
\node[rectangle, draw=none, inner sep=0pt,
minimum width=1mm, minimum height=10mm,
rotate=#1,
](s){};
%
\draw[rotate=#1] ([yshift=1mm]s.west)
-- ([yshift=1mm]s.east) coordinate[label=](P2)
-- (s.north east) coordinate[label=](Q2);
\draw[rotate=#1] ([yshift=-1mm]s.west)
-- ([yshift=-1mm]s.east) coordinate[label=](P1)
-- (s.south east) coordinate[label=](Q1);
}},%%
}
% 5b
\path[] ([xshift=-0.5mm]A1) pic{mypic={0}};
\draw pic [draw, angle radius=4mm, angle eccentricity=1.35,
"$\theta$", green!66!black, <-,
] {angle =A2s--A1--Q2};
\begin{scope}[decoration={
markings,
mark=at position 0.75 with {\arrow[red]{>}}}]
\path[draw=none, postaction=decorate] (P2) -- (Q2);
\end{scope}
% 5c
\path[] ([yshift=-0.5mm]A2) pic{mypic={90}};
\draw pic [draw, angle radius=4mm, angle eccentricity=1.75,
"$\theta'$", blue, <-,
] {angle =Q1--A2--B2};
\begin{scope}[decoration={
markings,
mark=at position 0.6 with {\arrow[red]{>}}}]
\path[draw=none, postaction=decorate] (P1) -- (Q1);
\end{scope}
% 6
\draw pic [draw, angle radius=1mm] {right angle =A2--A2s--A1};
\end{tikzpicture}
\end{document}
-
I think the length delta wasn't 100%. So I took the liberty of drawing another (dotted) guide line and correcting it.– cisCommented Oct 25 at 14:08
-
If I'm picky ... it's too long now. See this sketch: i.sstatic.net/TM3pNR1J.png– MS-SPOCommented Oct 25 at 14:30
-
1I wasn't sure how long it should be. According to his sketch it could be like mine. But in the code he learns enough TikZ-gimmicks; he should just adjust it as he needs it.– cisCommented Oct 25 at 16:29
-
1@€dit: I fixed that too at
% 3
. So he learns the syntax\draw[densely dotted, shorten >=-1mm] (A1) -- ($(A1)!2.25mm!-90:(B1)$) coordinate(A1s);
as well. `– cisCommented Oct 25 at 16:40 -
1I think the example in the starting post is very good because it basically contains all the basic TikZ knowledge. Anyone who understands and masters this code can draw anything with it.– cisCommented Oct 25 at 20:21