How can I draw the attached picture in LaTeX?
Asked
Active
Viewed 202 times
0
cfr
- 198,882
2 Answers
3
Just about does it...
\documentclass[tikz,border=5]{standalone}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}[dot/.style={insert path={ circle [radius=.05] }},
line cap=round, line join=round, >=stealth]
\draw (0,2) -- (4,4)
coordinate [pos=0.125] (A) coordinate [pos=0.5] (B) coordinate [pos=0.875] (C);
\draw (0,0) coordinate (O) -- (4,0) coordinate (O')
coordinate [pos=0.2] (D) coordinate [pos=0.5] (E) coordinate [pos=0.8] (F);
\foreach \x/\y/\z in {A/E/F, B/D/F, C/D/E}{
\draw [name path global=\x\y, blue!75!black] (\x) -- (\y);
\draw [name path global=\x\z, blue!75!black] (\x) -- (\z);
}
\foreach \x/\y/\z in {AE/BD/P, AF/CD/Q, BF/CE/R}
\path [name intersections={of/.expanded=\x\space and \y, name=i}]
(i-1) coordinate (\z);
\draw [thick, orange, dashed, shorten >=-1cm, shorten <=-1cm] (P) -- (R);
\foreach \n in {A, B, C} \fill (\n) [dot] node [above] {\n};
\foreach \n in {D, E, F} \fill (\n) [dot] node [below] {\n};
\foreach \n/\a in {P/340, Q/280, R/330}
\fill (\n) [dot] node [blue!75!black, anchor=\a] {\n};
\draw [ultra thick, ->, shorten >=-.125cm, red] (O) -- (O');
\draw [ultra thick, ->, red] (D) -- ++(0,3);
\end{tikzpicture}
\end{document}
Mark Wibrow
- 70,437
-
I just want to point out that (even without the
intersectionslibrary) you do not need to name paths in order to get intersections of lines: you can just use, e.g.,(intersection of A--E and B--D). – Emma Dec 03 '16 at 16:15
1
I agree with the comments of the users, certainly more skilled than me, but I answer the same because it might be useful to others, especially the use of intersections and macro definitions.
You have to set the macro \a, \b, \c, \d, \e, \f to the x value you want, then the macro \m \q respectively to the upper line slope and intercept.
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}[extended line/.style={shorten >=-#1,shorten <=-#1}, extended line/.default=1cm]
\pgfmathsetmacro\d{0}
\pgfmathsetmacro\e{2}
\pgfmathsetmacro\f{4}
\pgfmathsetmacro\m{0.4}
\pgfmathsetmacro\q{3}
\pgfmathsetmacro\a{-1}
\pgfmathsetmacro\b{2}
\pgfmathsetmacro\c{5}
\coordinate[label=above:$A$](A)at(\a,\m*\a+\q);
\coordinate[label=above:$B$](B)at(\b,\m*\b+\q);
\coordinate[label=above:$C$](C)at(\c,\m*\c+\q);
\coordinate[label=below:$D$](D)at(\d,0);
\coordinate[label=below:$E$](E)at(\e,0);
\coordinate[label=below:$F$](F)at(\f,0);
\draw[blue, name path=A--E](A)--(E);
\draw[blue, name path=B--D](B)--(D);
\draw[blue, name path=A--F](A)--(F);
\draw[blue, name path=C--D](C)--(D);
\draw[blue, name path=B--F](B)--(F);
\draw[blue, name path=C--E](C)--(E);
\path [name intersections={of=A--E and B--D,by=P}];
\path [name intersections={of=A--F and C--D,by=Q}];
\path [name intersections={of=B--F and C--E,by=R}];
\node[blue, above]at(P){$P$};
\node[blue, above]at(Q){$Q$};
\node[blue, above]at(R){$R$};
\draw [extended line=0.5cm] (A)--(B)--(C);
\draw [extended line=0.5cm] (D)--(E)--(F);
\draw [extended line=0.5cm, red , dashed] (P)--(Q)--(R);
\draw[red, ->] (\d-1,0)--(\f+1,0);
\draw[red, ->] (0,-1)--(0,\c);
\fill (A)circle(2pt) (B)circle(2pt) (C)circle(2pt) (D)circle(2pt) (E)circle(2pt) (F)circle(2pt);
\fill[blue] (P)circle(2pt) (Q)circle(2pt) (R)circle(2pt);
\end{tikzpicture}
\end{document}
josky
- 391
-
2(+1) You are perhaps aware of this, but note that one should be a little bit careful about
\pgfmathsetmacroand one letter macros (and other macro names, for that matter), as several one-letter macros are already defined: http://tex.stackexchange.com/questions/19111/short-names-for-macros.\pgfmathsetmacro, unlike\newcommand, does not check for existing definitions, so it will silently overwrite whatever that was. In this case you might be fine, as the definitions will be local to thetikzpictureenvironment I think, but something to keep in mind. – Torbjørn T. Dec 02 '16 at 10:02 -
@TorbjørnT. Thank you for your specifications. Your link is useful to keep in mind which variables can be edit. In a particular and specific case like this, I prefer not consider this caution. – josky Dec 02 '16 at 10:27


\includegraphics{}is a good emergency measure. For urgent, but not emergency use, samcarter's suggestion is probably a good one. – cfr Dec 01 '16 at 23:33