填充梯形部分

填充梯形部分

我有一个梯形,我需要填充这个梯形内的三角形 (F)。那么,是否有任何函数可以填充节点之间的空间或任何其他解决方案?非常感谢

\begin {center}
\begin {tikzpicture}

\draw[step=0.5, gray!60] (0,0) grid (8,6);
\foreach \x in {0,...,6}
{
\node[text=gray!60, left] at (0,\x) {$\x$};
}
\foreach \y in {1,...,8} {
\node[text=gray!60, below] at (\y,0) {$\y$};  
}

\node[inner sep=0pt,outer sep=0pt,minimum size=0pt](A) at(1,1){};
\node[inner sep=0pt,outer sep=0pt,minimum size=0pt](B) at(2,5){};
\node[inner sep=0pt,outer sep=0pt,minimum size=0pt](C) at(6,5){};
\node[inner sep=0pt,outer sep=0pt,minimum size=0pt](D) at(7,1){};
\node[label = $F$] at(5.5 ,3){};
\draw (A) -- (B) node[pos=.5,sloped,above] {$120 cm$};
\draw (C) -- (B) node[pos=.5,sloped,above] {$56 cm$};
\draw (C) -- (D) node[pos=.5,sloped,above] {$120 cm$};
\draw (A) -- (D) node[pos=.5,sloped,below] {$200 cm$};
\draw (B) -- (D);
\draw (A) -- (C);
\end {tikzpicture}
\end {center}

在此处输入图片描述

答案1

是的\fill。或者\filldraw,它还会绘制边框。您可以使用该intersections库来查找两条对角线之间的交点。

我还使用了\coordinate而不是\node来定义A等,我将单位放在数学模式之外(因为它们不应该像那样用斜体表示)。

代码输出

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}
\begin {center}
\begin {tikzpicture}

\draw[step=0.5, gray!60] (0,0) grid (8,6);
\foreach \x in {0,...,6}
{
\node[text=gray!60, left] at (0,\x) {$\x$};
}
\foreach \y in {1,...,8} {
\node[text=gray!60, below] at (\y,0) {$\y$};  
}

\coordinate (A) at (1,1);
\coordinate (B) at (2,5);
\coordinate (C) at (6,5);
\coordinate (D) at (7,1);

\draw (A) -- (B) node[pos=.5,sloped,above] {$120$ cm};
\draw (C) -- (B) node[pos=.5,sloped,above] {$56$ cm};
\draw (C) -- (D) node[pos=.5,sloped,above] {$120$ cm};
\draw (A) -- (D) node[pos=.5,sloped,below] {$200$ cm};
\draw [name path=a] (B) -- (D);
\draw [name path=b] (A) -- (C);

\filldraw[fill=blue!20,name intersections={of=a and b,by={M}}] (D) -- (M) -- (C) -- cycle;

\node at (barycentric cs:D=1,M=1,C=1) {$F$};
\end {tikzpicture}
\end {center}
\end{document}

相关内容