rectangle-varignon.tex 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. \documentclass[varwidth=true, border=2pt]{standalone}
  2. \usepackage{tikz}
  3. \usetikzlibrary{shapes, calc}
  4. \makeatletter
  5. \newcommand*\getX[1]{\expandafter\getX@i#1\@nil}
  6. \newcommand*\getY[1]{\expandafter\getY@i#1\@nil}
  7. \def\getX@i#1,#2\@nil{#1}
  8. \def\getY@i#1,#2\@nil{#2}
  9. \makeatother
  10. \begin{document}
  11. \begin{tikzpicture}
  12. % Define display style
  13. \tikzstyle{cross}=[cross out, draw, solid, red, inner sep=1.5pt, thick]
  14. \tikzstyle{diagonals}=[dashed, blue]
  15. % Define coordinates
  16. \newcommand\A{0,1}
  17. \newcommand\BX{3}
  18. \newcommand\BY{0}
  19. \newcommand\CX{4}
  20. \newcommand\CY{2}
  21. \newcommand\DX{1}
  22. \newcommand\DY{2}
  23. % Create shortcuts for coordinates and draw labels
  24. \coordinate[label=left:$A$] (A) at (\getX{\A}, \getY{\A});
  25. \coordinate[label=right:$B$] (B) at (\BX, \BY);
  26. \coordinate[label=above:$C$] (C) at (\CX, \CY);
  27. \coordinate[label=above:$D$] (D) at (\DX, \DY);
  28. \coordinate[label=below:$E$] (E) at ({(\getX{\A}+\BX)/2}, {(\getY{\A}+\BY)/2});
  29. \coordinate[label=right:$F$] (F) at ({(\BX+\CX)/2}, {(\BY+\CY)/2});
  30. \coordinate[label=above:$G$] (G) at ({(\CX+\DX)/2}, {(\CY+\DY)/2});
  31. \coordinate[label=left:$H$] (H) at ({(\DX+\getX{\A})/2}, {(\DY+\getY{\A})/2});
  32. % Draw the rectangle
  33. \draw[blue, thick] (A) -- (B) -- (C) -- (D) -- (A);
  34. % Draw the background of the parallelogram
  35. \draw[blue, fill=green!25] (E) -- (F) -- (G) -- (H) -- (E);
  36. % Draw the diagonals
  37. \draw[diagonals] (A) -- (C);
  38. \draw[diagonals] (B) -- (D);
  39. % Draw the parallelogram itself
  40. \draw[blue] (E) -- (F) -- (G) -- (H) -- (E);
  41. % Draw the crosses for each edge
  42. \foreach \coordinateName in {A, B, C, D}
  43. \node[cross] at (\coordinateName) {};
  44. \foreach \coordinateName in {E, F, G, H}
  45. \node[cross, gray!50!black] at (\coordinateName) {};
  46. \end{tikzpicture}
  47. \end{document}