我是新手蒂克兹(仍在学习),所以我不能创建复杂的tikzpicture
形状(只能创建简单的形状),但我想知道是否有人可以给我提供关于如何创建车辆悬架在简单的2D中。
类似于(但是在 2D 中):
答案1
这是第一次尝试(显然有待改进);基本上我使用了叠加的cylinder
s 和coilup
,coildown
装饰器this answer
经过汉斯·彼得·E·克里斯蒂安森:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing,patterns,shapes.geometric}
\usepgfmodule{decorations}
\makeatletter
% coilup, coildown decorations
% code by Hans-Peter E. Kristiansen
% in https://tex.stackexchange.com/a/43605/3954
% Parameters: \pgfdecorationsegmentamplitude, \pgfdecorationsegmentlength,
\pgfdeclaredecoration{coilup}{coil}
{
\state{coil}[switch if less than=%
1.5\pgfdecorationsegmentlength+%
\pgfdecorationsegmentaspect\pgfdecorationsegmentamplitude+%
\pgfdecorationsegmentaspect\pgfdecorationsegmentamplitude to last,
width=+\pgfdecorationsegmentlength]
{
\pgfpathcurveto
{\pgfpoint@oncoil{0 }{ 0.555}{1}}
{\pgfpoint@oncoil{0.445}{ 1 }{2}}
{\pgfpoint@oncoil{1 }{ 1 }{3}}
\pgfpathmoveto{\pgfpoint@oncoil{1 }{-1 }{9}}
\pgfpathcurveto
{\pgfpoint@oncoil{0.445}{-1 }{10}}
{\pgfpoint@oncoil{0 }{-0.555}{11}}
{\pgfpoint@oncoil{0 }{ 0 }{12}}
}
\state{last}[width=.5\pgfdecorationsegmentlength+%
\pgfdecorationsegmentaspect\pgfdecorationsegmentamplitude+%
\pgfdecorationsegmentaspect\pgfdecorationsegmentamplitude,next state=final]
{
\pgfpathcurveto
{\pgfpoint@oncoil{0 }{ 0.555}{1}}
{\pgfpoint@oncoil{0.445}{ 1 }{2}}
{\pgfpoint@oncoil{1 }{ 1 }{3}}
\pgfpathmoveto{\pgfpoint@oncoil{2 }{ 0 }{6}}
}
\state{final}
{
\pgfpathmoveto{\pgfpointdecoratedpathlast}
}
}
% coildown decoration
%
% Parameters: \pgfdecorationsegmentamplitude, \pgfdecorationsegmentlength,
\pgfdeclaredecoration{coildown}{coil}
{
\state{coil}[switch if less than=%
1.5\pgfdecorationsegmentlength+%
\pgfdecorationsegmentaspect\pgfdecorationsegmentamplitude+%
\pgfdecorationsegmentaspect\pgfdecorationsegmentamplitude to last,
width=+\pgfdecorationsegmentlength]
{
\pgfpathmoveto{\pgfpoint@oncoil{1 }{1 }{3}}
\pgfpathcurveto
{\pgfpoint@oncoil{1.555}{ 1 }{4}}
{\pgfpoint@oncoil{2 }{ 0.555}{5}}
{\pgfpoint@oncoil{2 }{ 0 }{6}}
\pgfpathcurveto
{\pgfpoint@oncoil{2 }{-0.555}{7}}
{\pgfpoint@oncoil{1.555}{-1 }{8}}
{\pgfpoint@oncoil{1 }{-1 }{9}}
}
\state{last}[width=.5\pgfdecorationsegmentlength+%
\pgfdecorationsegmentaspect\pgfdecorationsegmentamplitude+%
\pgfdecorationsegmentaspect\pgfdecorationsegmentamplitude,next state=final]
{
\pgfpathmoveto{\pgfpoint@oncoil{1 }{ 1 }{3}}
\pgfpathcurveto
{\pgfpoint@oncoil{1.555}{ 1 }{4}}
{\pgfpoint@oncoil{2 }{ 0.555}{5}}
{\pgfpoint@oncoil{2 }{ 0 }{6}}
}
\state{final}
{
\pgfpathlineto{\pgfpointdecoratedpathlast}
}
}
\def\pgfpoint@oncoil#1#2#3{%
\pgf@x=#1\pgfdecorationsegmentamplitude%
\pgf@x=\pgfdecorationsegmentaspect\pgf@x%
\pgf@y=#2\pgfdecorationsegmentamplitude%
\pgf@xa=0.083333333333\pgfdecorationsegmentlength%
\advance\pgf@x by#3\pgf@xa%
}
\makeatother
\definecolor{myorange}{RGB}{238,97,26}
\begin{document}
\begin{tikzpicture}
\draw[fill=gray!30]
(-0.5,-0.8) .. controls (-1.4,-2.3) and (1.4,-2.3) .. (0.5,-0.8);
\draw[fill=white]
(0,-1.3) circle (0.3cm);
\node[cylinder,
fill=myorange,
rotate=90,
draw,
minimum height=0.7cm,
minimum width=1.5cm,
anchor=east]
at (0,-0.15) {};
\node[cylinder,
fill=gray!30,
rotate=90,
draw,
minimum height=0.5cm,
minimum width=2cm,
anchor=east]
at (0,0.1) {};
\draw[decoration={
aspect=0.3,
segment length=3mm,
amplitude=10mm,coilup,
segment length=10pt},
decorate,
double=myorange,
double distance=2pt]
(0,5) -- (0,0);
\node[cylinder,
fill=gray!30,
rotate=90,
draw,
minimum height=2cm,
minimum width=0.4cm,
anchor=east,aspect=0.3]
at (0,2) {};
\node[cylinder,
fill,
rotate=90,
draw,
minimum height=3.1cm,
minimum width=1.4cm,
anchor=east]
at (0,5) {};
\draw[decoration={
aspect=0.3,
segment length=3mm,
amplitude=10mm,coildown,
segment length=10pt},
decorate,
double=myorange,
double distance=2pt]
(0,5) -- (0,0);
\node[cylinder,
fill=gray!30,
rotate=90,
draw,
minimum height=0.5cm,
minimum width=2cm,
anchor=east]
at (0,5.2) {};
\node[cylinder,
fill,
rotate=90,
draw,
minimum height=1cm,
minimum width=1.4cm,
anchor=east]
at (0,6) {};
\node[cylinder,
fill=gray!30,
rotate=90,
draw,
minimum height=0.5cm,
minimum width=1.6cm,
anchor=east]
at (0,6) {};
\draw[fill=gray!30]
(-0.5,5.9) .. controls (-1.4,7.5) and (1.4,7.5) .. (0.5,5.9);
\draw[fill=white]
(0,6.5) circle (0.3cm);
\end{tikzpicture}
\end{document}
答案2
绘制示意图(不仅仅在TikZ
)的窍门是将事物分解成非常基本的形式。举个悬架的例子:您不必关心“我该如何让弹簧绕组看起来部分位于阻尼杆后面,部分位于前面?”,而是减少东西以使其简单但易于识别。例如,在物理或技术图纸中表示弹簧的典型锯齿线应该足够接近,以便看到您的意思。
第二个非常有用的功能TikZ
是泛化。您可以轻松为某些事物定义自己的样式或宏。例如,如果您希望所有绘图中的线程都是黑色且带有锯齿状边缘,则可以定义一个全局样式来实现这一点,然后将此样式应用于您想要绘制的所有线程。
想要了解所有可能的事情以及它们背后的代码,请查看texample.net。您会惊讶地发现,绘制非常精致的图形只需要很少的代码。在许多情况下,您不会立即理解整个代码,但不要放弃,而是拿起代码并尝试一下,看看编辑后情况会如何变化。这将使您逐步学习新功能,并使您能够更详细、更直接地解决问题。
不要太早放弃,TikZ
学习曲线可能会相当陡峭。特别是如果你心里有想要实现的某个绘图,你会认为你永远无法实现它,但你必须一步一步地解决一个又一个问题。最重要的是:随时准备好手册TikZ
,最好是电脑上随时打开的 PDF 格式。它包含一些不错的入门教程,非常全面,几乎解释了每一段代码。
除此之外,还有一些基于其的包TikZ
,它们定义了一些额外的功能,例如绘制电路、绘制数据等。我不知道是否已经有用于绘制机械东西的东西,但我不会感到惊讶。