答案1
这是一个可行的解决方案(不包括中文字符)。我使用 Ti钾Zcalc
库查找三角形边缘的中心点(其实不是必需的),然后我首先放置所有需要的坐标。代码可以减少,但我认为这种方式更具解释性。
\documentclass {standalone}
\usepackage {tikz}
\usetikzlibrary{calc} % for midpoints like ($(A)!0.5!(B)$)
\begin{document}
\begin{tikzpicture}
% coordinates
\coordinate (A) at (7,4);
\coordinate (B) at (3,7);
\coordinate (C) at (3,4);
\coordinate (D) at (7,7);
\coordinate (E) at (0,3);
\coordinate (F) at (4,0);
\coordinate (O) at (0,0);
\useasboundingbox (-1,-1) rectangle (8,8); % for centering wrt the grid (probably not necessary)
% drawing
\fill[pink!50] (A) -- (B) -- (E) -- (F) -- cycle; % big square background
\draw[gray] (O) grid (D); % grid
\draw[thick] (A) -- (B) -- (E) -- (F) -- cycle; % big square
\draw[blue,thick] (B) |- (A); % line from B to A, first vertical then horizontal
\draw[blue,thick] (E) -| (F); % line from E to F, first horizontal then vertical
\draw[blue,thick,fill=yellow] (3,3) rectangle (4,4); % little square
% points and labels
\foreach\i in {A,B,C} % points and red dots
\fill[red] (\i) circle (2pt) node [above right] {$\i$};
\node[red] at (D) [above right] {$D$}; % dotless point
\node[red] at ($(B)!0.5!(C)$) [right] {$a$}; % midpoint between B and C
\node[red] at ($(A)!0.5!(C)$) [above] {$b$}; % midpoint between A and C
\node[red] at ($(A)!0.5!(B)$) [above right] {$c$}; % midpoint between A and B
\end{tikzpicture}
\end{document}
答案2
您的图像的副本
首先,我会复制你想要绘制的图像
\begin{tikzpicture}
% Colors define
\definecolor{myRed}{HTML}{A43A44}
\definecolor{myOrange}{HTML}{F9EAE3}
\definecolor{myYellow}{HTML}{ECCB46}
% Important positions
\node (A) at (7,4) {};
\node (B) at (3,7) {};
\node (C) at (3,4) {};
\node (D) at (7,7) {};
% Big rectangle color
\fill[myOrange,opacity=0.7] (4,0) -- (0,3) -- (B.center) -- (A.center) -- cycle;
% Here we draw the grid and te colored square
\fill[myYellow] (3,3) rectangle (4,4);
\draw[] (0,0) grid (7,7);
% Big rectangle
\draw[very thick] (4,0) -- (0,3) -- (B.center) -- (A.center) node[midway,myRed]{\textbf{c}} -- cycle;
% Position labels
\node at (A.east) [xshift=5] {\textbf{A}};
\node at (B.north) [yshift=5] {\textbf{B}};
\node at (C.west) [xshift=-5] {\textbf{C}};
\node at (D.north east) [xshift=1,yshift=1] {\textbf{D}};
% Thicker lines of the box
\draw[thick] (C.center) -- (A.center) node[midway,myRed]{\textbf{b}};
\draw[thick] (3,3) -- (B.center) node[midway,myRed]{\textbf{a}};
\draw[thick] (4,3) -- (0,3);
\draw[thick] (4,4) -- (4,0);
% Circles
\foreach \n in {A,B,C}
\fill[myRed] (\n.center) circle[radius=0.07];
\end{tikzpicture}
但我会对我的代码做一些解释。
解释
我做的第一件事就是制作图像中的颜色,这样它就尽可能接近你的颜色。
\definecolor{myRed}{HTML}{A43A44}
然后我定义了图像中出现的重要位置。
\node (A) at (7,4) {};
上述代码创建了一个节点,其名称A
位于该位置(7,4)
,并且没有标签{}
(需要空括号)。
之后我制作了正方形的彩色部分,因为我认为它看起来像在网格后面
\fill[myOrange,opacity=0.7] (4,0) -- (0,3) -- (B.center) -- (A.center) -- cycle;
(x,y)
如您所见,我将法线坐标和节点坐标进行了组合(name.position)
。
然后我制作了黄色正方形和网格
\fill[myYellow] (3,3) rectangle (4,4);
\draw[] (0,0) grid (7,7);
(必须按顺序排列,以避免颜色超出线条的部分)
在下一部分中,我制作了大正方形的边框
\draw[very thick] (4,0) -- (0,3) -- (B.center) -- (A.center) node[midway,myRed]{\textbf{c}} -- cycle;
正如您所看到的,我在A
代码中的顶点后添加了node[midway,myRed]{\textbf{c}}
一个节点,这告诉 tikz 将一个带有标签的节点\textbf{c}
放在我们例子中前两个节点的中间A
。B
然后我添加了节点标签
\node at (A.east) [xshift=5] {\textbf{A}};
我使用与坐标相同的节点名称语法来标记点,并添加了一点点偏移,因为这样看起来更好。
最后我添加了一个小循环
\foreach \n in {A,B,C}
\fill[myRed] (\n.center) circle[radius=0.07];
它获取每个节点并在其中画一个圆圈。
局部放电
我制造了一个文档如果你有兴趣,可以附上代码和我自己的版本,抱歉,但我不知道如何添加其他字符
答案3
另一种解决方案是,在绘图时calc
通过选项插入标签pos
paths
\documentclass[tikz,border=2mm]{standalone}
\begin{document}
\begin{tikzpicture}[
mylabel/.style={red, opacity=1},
dot/.style={circle, inner sep=0pt, minimum size=4pt, fill=red, draw=none, opacity=1}]
\draw[help lines] (0,0) grid (7,7);
\draw[thick, fill=red!20, fill opacity=.5] (0,3) -- (3,7) node[dot, label={[mylabel, above right]$B$}] {} -- node[midway, mylabel, above right]{$c$} (7,4) node[dot, label={[above right, mylabel]$A$}]{}--(4,0)--cycle;
\draw[blue, fill=yellow] (3,3) rectangle (4,4);
\draw[blue, thick] (0,3)-|(4,0) (3,7)|-node[pos=0.25, red, right] {$a$} node[pos=0.5, dot, label={[mylabel, above right]$C$}]{} node[pos=0.75, red, above]{$b$} (7,4);
\end{tikzpicture}
\end{document}
答案4
我认为标签没有必要。另请参阅这个答案。
\documentclass[tikz,border=5mm]{standalone}
\begin{document}
\begin{tikzpicture}[join=round,
tri345/.pic={\draw[thick,red,fill=pink!50] (0,0)--(4,0)--(0,3)--cycle;}]
\fill[yellow] (0,0) rectangle (1,-1);
\path
(0,0) pic{tri345}
+(1,-1) pic[scale=-1]{tri345}
+(0,-1) pic[rotate=90]{tri345}
+(1,0) pic[rotate=-90]{tri345};
\draw[gray] (-3,-4) grid (4,3);
\end{tikzpicture}
\end{document}