I am trying to draw an EKG tracing using TikZ. This is an of a single heartbeat on an EKG. The following code generates an acceptable simulacrum, but it's hard to use this code as a generator.
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\newcommand{\PR}[1]{\draw (0,0) -- (#1,0);}
\newcommand{\QRS}[2]
{
\draw (0,0) -- (#2/2,#1) -- (#2,0);
}
\newcommand{\ST}[1]
{
\draw (0,0) -- (#1/3,0);
\draw (#1/3,0) arc (180:0:#1/3);
\draw (#1,0) -- (#1*1.5,0);
}
\begin{document}
\begin{tikzpicture}
\PR{2}
\begin{scope}[shift={(2,0)}]
\QRS{3}{2}
\end{scope}
\begin{scope}[shift={(4,0)}]
\ST{2}
\end{scope}
\end{tikzpicture}
\end{document}
I tried to stick the code in a function:
\newcommand{\RR}[1]
{
%Healthy PR segment duration upper bound = 0.20s
%Healthy QRS segment duration upper bound = 0.12s
%Healthy ST segment duration upper bount = 0.12s
%Fix QRS amplitude for now
%This inspires the ratio, 2/1/1
\PR{#1/2}
\begin{scope}[shift={(#1,0)}]
\QRS{3}{#1/4}
\begin{scope}[shift={(#1/2,0)}]
\ST{#1/4}
\begin{scope}[shift=(#1/2,0)]
\PR{#1/2}
\end{scope}
\end{scope}
\end{scope}
%Yes I know this sums to more than 1.
}
This function times out, presumably because of all the nested scopes. How can I draw an EKG more elegantly?
scope
s are not loops. I assume that you meant to have a loop, right? – A.Ellett May 19 '15 at 19:14scope
statements. – mac389 May 19 '15 at 19:53