mirror of
https://github.com/MartinThoma/LaTeX-examples.git
synced 2025-04-26 06:48:04 +02:00
61 lines
1.8 KiB
TeX
61 lines
1.8 KiB
TeX
\documentclass[varwidth=true, border=2pt]{standalone}
|
|
\usepackage{tikz}
|
|
\usetikzlibrary{shapes, calc}
|
|
|
|
\makeatletter
|
|
\newcommand*\getX[1]{\expandafter\getX@i#1\@nil}
|
|
\newcommand*\getY[1]{\expandafter\getY@i#1\@nil}
|
|
\def\getX@i#1,#2\@nil{#1}
|
|
\def\getY@i#1,#2\@nil{#2}
|
|
\makeatother
|
|
|
|
\begin{document}
|
|
\begin{tikzpicture}
|
|
% Define display style
|
|
\tikzstyle{cross}=[cross out, draw, solid, red, inner sep=1.5pt, thick]
|
|
\tikzstyle{diagonals}=[dashed, blue]
|
|
|
|
% Define coordinates
|
|
\newcommand\A{0,1}
|
|
|
|
\newcommand\BX{3}
|
|
\newcommand\BY{0}
|
|
|
|
\newcommand\CX{4}
|
|
\newcommand\CY{2}
|
|
|
|
\newcommand\DX{1}
|
|
\newcommand\DY{2}
|
|
|
|
% Create shortcuts for coordinates and draw labels
|
|
\coordinate[label=left:$A$] (A) at (\getX{\A}, \getY{\A});
|
|
\coordinate[label=right:$B$] (B) at (\BX, \BY);
|
|
\coordinate[label=above:$C$] (C) at (\CX, \CY);
|
|
\coordinate[label=above:$D$] (D) at (\DX, \DY);
|
|
|
|
\coordinate[label=below:$E$] (E) at ({(\getX{\A}+\BX)/2}, {(\getY{\A}+\BY)/2});
|
|
\coordinate[label=right:$F$] (F) at ({(\BX+\CX)/2}, {(\BY+\CY)/2});
|
|
\coordinate[label=above:$G$] (G) at ({(\CX+\DX)/2}, {(\CY+\DY)/2});
|
|
\coordinate[label=left:$H$] (H) at ({(\DX+\getX{\A})/2}, {(\DY+\getY{\A})/2});
|
|
|
|
% Draw the rectangle
|
|
\draw[blue, thick] (A) -- (B) -- (C) -- (D) -- (A);
|
|
|
|
% Draw the background of the parallelogram
|
|
\draw[blue, fill=green!25] (E) -- (F) -- (G) -- (H) -- (E);
|
|
|
|
% Draw the diagonals
|
|
\draw[diagonals] (A) -- (C);
|
|
\draw[diagonals] (B) -- (D);
|
|
|
|
% Draw the parallelogram itself
|
|
\draw[blue] (E) -- (F) -- (G) -- (H) -- (E);
|
|
|
|
% Draw the crosses for each edge
|
|
\foreach \coordinateName in {A, B, C, D}
|
|
\node[cross] at (\coordinateName) {};
|
|
|
|
\foreach \coordinateName in {E, F, G, H}
|
|
\node[cross, gray!50!black] at (\coordinateName) {};
|
|
\end{tikzpicture}
|
|
\end{document}
|