以下代码来自这个帖子可用于绘制任意边数的彩色正多边形。它可绘制等边三角形。
是否可以修改此代码以绘制等腰三角形(边长可控制),如下图所示!
\documentclass[10pt,a4paper]{article}
\usepackage{tikz,xparse}
\usetikzlibrary{calc}
\pgfmathsetmacro{\lwdthc}{.2mm}
\newif\iffill
\begin{document}
\tikzset{%
patron/.style={%
line join=round, rounded corners=.05pt, draw, line width=\lwdthc},
patron side/.style={patron},
patron languette/.style={patron},%
}
\newcounter{NodePat}
\NewDocumentCommand{\PolygReg}{%
O{3}%
O{}
m%
O{A}%
}
{%
\ifx\relax#2\relax
\iffill
\ifnum#1=3 \def\tmp{fill=blue!25!white}\else
\ifnum#1=4 \def\tmp{fill=blue!28!white}\else
\ifnum#1=5 \def\tmp{fill=blue!31!white}\else
\ifnum#1=6 \def\tmp{fill=blue!34!white}\else
\ifnum#1=7 \def\tmp{fill=blue!37!white}\else
\ifnum#1=8 \def\tmp{fill=blue!40!white}\else
\ifnum#1=9 \def\tmp{fill=blue!43!white}\else
\ifnum#1=10 \def\tmp{fill=blue!46!white}\else
\def\tmp{}\fi\fi\fi\fi\fi\fi\fi\fi
\else
\def\tmp{}%
\fi
\else
\def\tmp{#2}%
\fi
\foreach \a/\b in {#3}
{%
\expandafter\path\expandafter[\tmp, patron side] let%
\p1 = ($(\a)!.5!(\b)$) ,
\n1 = {veclen(\x1,\y1)} ,
\p2 = ($(\p1)!1/tan(180/#1)!90:(\b)$)
in
(\a)--(\b)
\foreach \i [%
evaluate=\i as \j using (\i-1)*360/#1] in {3,...,#1} {%
-- ($(\p2)!1!\j:(\a)$) coordinate (#4\theNodePat)
\pgfextra{\stepcounter{NodePat}}
}
-- cycle ;
}
}
\NewDocumentCommand{\Languette}{%
O{.15} %
D<>{24} %
m %
D<>{24} %
O{A}
}%do not leave an empty line after it
{%
\foreach \b/\a in {#3} {%
\path[patron languette, fill=yellow] let
\p1 = ($(#5\b)!#1/sin(#2)!-#2:(#5\a)$),
\p2 = ($(#5\a)!#1/sin(#4)!#4:(#5\b)$)
in
(#5\a) -- (#5\b) -- (\p1) -- (\p2) -- cycle ; }
}
\makeatletter
\newcommand{\AffNodesPatron}[1][A]{%
\newcount\X
\X=1
\loop
\expandafter\ifx\csname pgf@sh@pi@A\the\X\endcsname\pgfpictureid
\node[font={\footnotesize},red] at (A\the\X) {A\the\X} ;
\advance \X by 1
\else
\X=0
\fi
\unless\ifnum \X=0
\repeat
}
\makeatother
\filltrue
\begin{tikzpicture}[scale=3]
\coordinate (A1) at (0,0) ;
\coordinate (A2) at (0,-1) ;
\setcounter{NodePat}{3}
\PolygReg[3]{A1/A2}
\PolygReg[4]{A3/A2}
\PolygReg[5]{A3/A5}
\PolygReg[6]{A7/A6}
\Languette{3/1}
\AffNodesPatron
\draw [draw=none] (A1.center) -- (A3.center) node [purple, pos=.5, xshift=.4cm,yshift=0cm] {\bf B};
\end{tikzpicture}
\end{document}