在 TIKZ 中构建图形(带有彩色形状)

在 TIKZ 中构建图形(带有彩色形状)

我正在尝试在 TIKZ 上绘制这个图形,但是在第一个图形上我在以下两点上有点卡住了: 1用红色填充圆圈 2我想要的不是圆形,而是更通用的“形状” 在此处输入图片描述

这是我到目前为止仅用圆圈所做的:

\begin{tikzpicture}[scale=0.8]
% Initial and target points
\coordinate (start) at (0,0);
\coordinate (end) at (10,3);

% Circle 1
\draw (2.5,2) circle (1.2);
%\node at (2.5,2) {$t_1$};

% Circle 2
\draw (7.5,2) circle (1.2);
%\node at (7.5,2) {$t_3$};

% Trajectory
\draw[smooth,thick] plot[smooth] coordinates{(0,0) (1,0.3) (2,1.5) (2.25,1.75) (2.5,2) (2.75,1.75) (3,1.5) (4,0) (5,0) (6,0) (7.5,2) (8.5,2.5) (9,5) (10,3)};

% Time axis
\draw[->] (0,-1) -- (10,-1) node[right] {$t$};
\foreach \t/\label in {0/$0$,2/$t_1$,3/$t_2$,6/$t_3$,7/$t_4$,10/$T$} {
    \draw (\t,-0.9) -- (\t,-1.1) node[below] {\label};
}

 \filldraw (0,0) circle (2pt);
  \filldraw (10,3) circle (2pt);
% Label for initial and target points
\node[above] at (start) {Initial point};
\node[above] at (end) {Target point};

\结束{tikzpicture}

生成以下内容:

在此处输入图片描述

答案1

欢迎来到 TeX.SE!!!

你可以用贝塞尔曲线绘制形状和线条,或者像我一样用to[in=...,out=...]。例如

\draw (A) to[out=30,in=120] (B);

绘制一条曲线,以 30 度角从 A 处开始,以 120 度角从 B 处结束(两个角度均相对于 x 轴)。

一个完整的例子可能是:

\documentclass[tikz,border=1.618]{standalone}

\tikzset{point/.style={circle,draw=black,fill=white,inner sep=1pt}}

\begin{document}
\begin{tikzpicture}[thick]
% dimensions and coordinates
\def\xa{1.5}
\def\xb{4}
\def\xc{5.3}
\def\xd{8.3}
\coordinate (P1) at (\xa,2.5);
\coordinate (P2) at (\xb,2.3);
\coordinate (P3) at (\xc,2.2);
\coordinate (P4) at (\xd,2);
% axes and blue dashed lines
\foreach\i in {0,-4.5}
{
  \draw[blue]    (-0.5,\i) --   (10,\i);
  \draw[blue]   (0,\i+0.1) --++ (0,-0.2) node[below] {\strut$0$};
  \draw[blue] (9.5,\i+0.1) --++ (0,-0.2) node[below] {\strut$T$};
}
\foreach[count=\ii]\i in {\xa,\xb,\xc,\xd}
{
  \draw[blue,dashed] (P\ii)    -- (\i,0)    node[below] {\strut$t_\ii$};
  \draw[blue,dashed] (\i,-1.5) -- (\i,-4.5) node[below] {\strut$t_\ii$};
}
% shapes
\draw[thin,fill=red!40] (P1) to[out=120,in=170] ++ (1,1.2)   to[out=-10,in=180] ++ (0.7,0.2) to[out=0,in=50]
                        (P2) to[out=230,in=0]   ++ (-2,-1)   to[out=180,in=-60] cycle;
\draw[thin,fill=red!40] (P3) to[out=110,in=210] ++ (1.3,1.5) to[out=30,in=90]   ++ (2,-1) to[out=270,in=30]
                        (P4) to[out=210,in=0]   ++ (-2,-0.6) to[out=180,in=-70] cycle;
% curves
\draw (0,1.8) node[point] {} to[out=30,in=190] (P1) to[out=10,in=170]  (P2) to[out=-10,in=190]
                        (P3) to[out=10,in=150] (P4) to[out=-30,in=170] (9.5,1.5) node[point] {};
\draw[red,dashed] (0,-4) to[out=70,in=110] ++ (0.8,0.6) to[out=-70,in=240] (\xa,-2.5);
\draw[red]        (\xa,-2.3) -- (\xb,-2.3);
\draw[red,dashed] (\xb,-3.3) to[out=20,in=200] (\xc,-1.7);
\draw[red]        (\xc,-4) -- (\xd,-4);
\draw[red,dashed] (\xd,-3.3) to[out=0,in=180] (9.5,-3.7);
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容