Skip to content

Instantly share code, notes, and snippets.

@johnwickerson
Created February 16, 2019 21:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnwickerson/1fadc7cbe799514605f44a9c72eaede1 to your computer and use it in GitHub Desktop.
Save johnwickerson/1fadc7cbe799514605f44a9c72eaede1 to your computer and use it in GitHub Desktop.
Area of a parallelogram
% convert -delay 200 -loop 0 -dispose previous -density 300 parallelogram.pdf parallelogram.gif
\documentclass[border=5pt,tikz]{standalone}
\usetikzlibrary{intersections, calc, through}
\usepackage{pagecolor}
\begin{document}
\pagecolor{white}
\tikzset{
guide/.style={dotted},
main/.style={draw=red, line width=2pt, line join=round},
}
\def\xmax{4}
\def\ymax{4}
\def\a{3}
\def\c{0.5}
\def\b{1}
\def\d{2.5}
\def\colorA{black!20}
\def\colorB{orange!40}
\def\colorC{blue!30}
\def\colorD{green!30}
\newcommand\commonpart{
\node[anchor=south west, inner sep=0] at (0,\ymax) {\begin{tabular}{@{}l}
A wordless proof that the \\
parallelogram defined by \\
vectors $(a,b)$ and $(c,d)$ \\
has area $ad-bc$.
\end{tabular}};
\path[name path=xaxis] (0,0) to (\xmax,0);
\path[name path=yaxis] (0,0) to (0,\ymax);
\node[anchor=east] at (0,\b) {$b$};
\node[anchor=east] at (0,\d) {$d$};
\node[anchor=north] at (\a,0) {$a$};
\node[anchor=north] at (\c,0) {$c$};
\draw[guide, name path=la](\a,0) to (\a,\ymax);
\draw[guide](\c,0) to (\c,\ymax);
\draw[guide](\a+\c,0) to (\a+\c,\ymax);
\draw[guide](0,\b) to (\xmax,\b);
\draw[guide, name path=ld](0,\d) to (\xmax,\d);
\draw[guide](0,\b+\d) to (\xmax,\b+\d);
\coordinate(r1) at (\a-\c,0);
\coordinate(r2) at (0,\d-\b);
}
\newcommand\axes{
\draw[-latex] (0,0) to (\xmax,0);
\draw[-latex] (0,0) to (0,\ymax);
}
\begin{tikzpicture}[line width=1pt]
\commonpart
\axes
\draw[main](0,0) -- (\a,\b) -- (\a+\c,\b+\d) -- (\c,\d) -- cycle;
\end{tikzpicture}
\begin{tikzpicture}[line width=1pt]
\commonpart
\draw[draw=none, fill=\colorA] (\c,\d) -- (\a+\c,\b+\d) -- (\a,\d) -- cycle;
\draw[draw=none, fill=\colorB] (\a,\b) -- (\a+\c,\b+\d) -- (\a,\d) -- cycle;
\draw[draw=none, fill=\colorA] (r1) -- (\a,\b) -- (0,0) -- cycle;
\draw[draw=none, fill=\colorB] (r2) -- (\c,\d) -- (0,0) -- cycle;
\axes
\draw[-latex] (0,0) to (\xmax,0);
\draw[-latex] (0,0) to (0,\ymax);
\draw[main](0,0) -- (\a,\b) -- (\a+\c,\b+\d) -- (\c,\d) -- cycle;
\end{tikzpicture}
\begin{tikzpicture}[line width=1pt]
\commonpart
\draw[draw=none, fill=\colorA] (\c,\d) -- (\a+\c,\b+\d) -- (\a,\d) -- cycle;
\draw[draw=none, fill=\colorB] (\a,\b) -- (\a+\c,\b+\d) -- (\a,\d) -- cycle;
\draw[draw=none, fill=\colorA] (r1) -- (\a,\b) -- (0,0) -- cycle;
\draw[draw=none, fill=\colorB] (r2) -- (\c,\d) -- (0,0) -- cycle;
\axes
\draw[main](0,0) -- (r1) -- (\a,\b) -- (\a,\d) -- (\c,\d) -- (r2) -- cycle;
\end{tikzpicture}
\begin{tikzpicture}[line width=1pt]
\commonpart
\axes
\draw[main](0,0) -- (r1) -- (\a,\b) -- (\a,\d) -- (\c,\d) -- (r2) -- cycle;
\end{tikzpicture}
\begin{tikzpicture}[line width=1pt]
\commonpart
\draw[draw=none, fill=\colorC] (r2) -- (0,\d) -- (\c,\d) -- cycle;
\draw[draw=none, fill=\colorC] (0,0) -- (0,\b) -- (\c,\b) -- cycle;
\draw[draw=none, fill=\colorD] (0,0) -- (\c,0) -- (\c,\b) -- cycle;
\draw[draw=none, fill=\colorD] (r1) -- (\a,0) -- (\a,\b) -- cycle;
\axes
\draw[main](0,0) -- (r1) -- (\a,\b) -- (\a,\d) -- (\c,\d) -- (r2) -- cycle;
\end{tikzpicture}
\begin{tikzpicture}[line width=1pt]
\commonpart
\draw[draw=none, fill=\colorC] (r2) -- (0,\d) -- (\c,\d) -- cycle;
\draw[draw=none, fill=\colorC] (0,0) -- (0,\b) -- (\c,\b) -- cycle;
\draw[draw=none, fill=\colorD] (0,0) -- (\c,0) -- (\c,\b) -- cycle;
\draw[draw=none, fill=\colorD] (r1) -- (\a,0) -- (\a,\b) -- cycle;
\axes
\draw[main](0,\b) -- (\c,\b) -- (\c,0) -- (\a,0) -- (\a,\d) -- (0,\d) -- cycle;
\end{tikzpicture}
\begin{tikzpicture}[line width=1pt]
\commonpart
\axes
\draw[main](0,\b) -- (\c,\b) -- (\c,0) -- (\a,0) -- (\a,\d) -- (0,\d) -- cycle;
\end{tikzpicture}
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment