I want to draw a mechanical wagoon for a physics book with a parameterized approach.
These should be the parameters:
#0 name, the name of the object, e.g. mywagon
#1 position of the wagon as coordinate, center below at the height of the ground e.g. (4.5,0)
#2 (optional) width of the mass, e.g. 5, default value 3
#3 (optional) height of the mass, e.g. 4, default 2/3*width
#4 (optional) wheel: the diameter of the wheel, default 1/5*width
#5 (optional) gap: the gap between edge of mass and wheel, default 1/10*wheel
#6 (optional) overlap: The overlap of mass and wheel, default 1/3*wheel
The call in tikz should then look something like this:
\begin{tikzpicture}
\draw[ground] (0,0) -- (9,0);%ground
\wagoon[name=mywagon, width=5, height=4.2, wheel=1.1, gap=0.6, overlap=0.4] at (4.5,0);
\draw[rope] mywagon-mass.east -- ++(1,0);
\draw[rope] mywagon-mass.west -- ++(-1,0);
\draw[arrow] mywagon-wheel-2.center -- ++(2,0);
\draw[ground] (0,-6) -- (9,-6);%ground
\wagon[name=mywagon2, width=5, very thick, red] at (4.5,-6);%with defaults of other optional parameters and then additional very thick and red
\end{tikzpicture}
The wagoon should consist out of normal nodes: Ohne rectangle and two circles
In the further course of use, it should be possible to access the anchors in the drawing via the object.anchor notation. This is important, for example to attach ropes to the wagoon afterwards.
The names of the sub-nodes inside should be:
<name>-mass for the mass, e.g. mywagon-mass
<name>-wheel-1 and <name>-wheel-2 for the wheels, e.g. mywagon-wheel-1 and mywagon-wheel-2
where <name> is the value of parameter #0 named name
Of course, I could make a non-parameterized drawing of this wagon, but I don't think that's helpful here, but rather annoying, because then you might adopt wrong approaches from me in the structure of the drawing.
It is important that the tikz code for the wagon is stored in the preamble so that the code is also available in other drawings.
\documentclass[border=10pt]{standalone}%
\usepackage{tikz}
\usetikzlibrary{arrows}
\tikzset{
mass/.style={rectangle, draw, thick, fill=gray!25},%
wheel/.style={circle, draw, thick, fill=white}},%
wheelaxle/.style={circle, draw, fill}},%
rope/.style={blue, thick},%
ground/.style={thick},%
arrow/.style={-latex, thick},%
}
% global tikz-code here
\begin{document}
\begin{tikzpicture}
\draw[ground] (0,0) -- (9,0);%ground
%\wagoon[name=mywagon, width=5, height=4.2, wheel=1.1, gap=0.6, overlap=0.4] at (4.5,0);
\draw[rope] mywagon-mass.east -- ++(1,0);
\draw[rope] mywagon-mass.west -- ++(-1,0);
\draw[arrow] mywagon-wheel-2.center -- ++(2,0);
\draw[ground] (0,-6) -- (9,-6);%ground
%\wagoon[name=mywagon2, width=5, very thick, red] at (4.5,-6);%with defaults of other optional parameters and then additional very thick and red
\end{tikzpicture}
\end{document}