Para obter um triângulo equilátero eu uso
\tikzstyle{triangle} = [fill=green!20, regular polygon, regular polygon sides=3]
Mas estou lutando para definir o nó tikz para o triângulo retângulo
pensei em fazer algo assim
\tikzstyle{anytriangle} = [draw, A--B--C--A]
e então
\begin{tikzpicture}[ auto, node distance=4em]
% Gridline
\draw [step=0.5cm,draw=gray] (-4,-4) grid (4,4);
\coordinate (A) at (0,0);
\coordinate (B) at (4,0);
\coordinate (C) at (0,4);
\node [anytriangle] {};
\end{tikzpicture}
Mas recebo um erro: coordenada desconhecida A
Responder1
Talvez assim (mas devo admitir que não entendo completamente o que você deseja alcançar):
\documentclass[tikz]{standalone}
\begin{document}
\tikzset{triangle/.append style={fill=green!20, regular polygon, regular polygon sides=3},
anytriangle/.append style={draw, append after command={ \pgfextra{ \draw (A) -- (B) -- (C) -- (A); } }}}
\begin{tikzpicture}[auto, node distance=4em]
% Gridline
\draw [step=0.5cm,draw=gray] (-4,-4) grid (4,4);
\coordinate (A) at (0,0);
\coordinate (B) at (4,0);
\coordinate (C) at (0,4);
\node [anytriangle] {};
\end{tikzpicture}
\end{document}
Responder2
Você pode usar uma isosceles triangle
forma com apex angle=90
.
\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{positioning, shapes.geometric}
\begin{document}
\begin{tikzpicture}[
right angle triangle/.style={
isosceles triangle,
isosceles triangle apex angle=90},
every node/.style={right angle triangle,
draw, inner sep=0pt,
anchor=left corner,
shape border rotate=90},
paint/.style={draw=#1!75, fill=#1!20}
]
\draw[help lines] grid (5,2);
\foreach \a/\c in {1.5/blue, 1/green, 0.5/red}{
\node[paint=\c, minimum width=\a cm] at (0,0) {};
\node[paint=\c, minimum height=\a cm] at (2,0) {};
}
\begin{scope}[yshift=-3cm,
every node/.style={
right angle triangle,
isosceles triangle stretches=false,
draw, inner sep=0pt,
minimum height=1cm,
anchor=apex}
]
\draw[help lines] (0,0) grid (2,2);
\foreach \a/\c in {45/blue, 135/green,225/red,315/orange}
\node[paint=\c,
shape border rotate=\a] at (1,1) {};
\end{scope}
\end{tikzpicture}
\end{document}
Responder3
pela sua pergunta eu entendi que você está procurando por isso:
rotulei as coordenadas A, B e C por pinos (como você pode ver, esse triângulo combina perfeitamente com ele.
para as imagens acima, sugiro duas soluções:
- use triângulo isósceles (semelhante aIgnasiresponder:
\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{tikzpicture}[
trian/.style = {isosceles triangle,
isosceles triangle apex angle=90,
minimum size=4cm/sqrt(2), inner sep=0pt,
anchor=east,rotate=-135,
draw, fill=green!20}
]
\coordinate[pin=below:A] (A) at (0,0);
\coordinate[pin=below:B] (B) at (4,0);
\coordinate[pin=C] (C) at (0,4);
%
\node [trian] {};
\end{tikzpicture}
\end{document}
- com imagem pequena (
\pic
), que não são nós, mas possuem características semelhantes (de possíveis nós âncoras defino apenas três cantos como-a
,-b
e ˙-c`):
\documentclass[tikz, margin=3mm]{standalone}
\begin{document}
\begin{tikzpicture}[
trian/.pic = {
\draw [fill=green!20]
(0,0) coordinate (-a) --
(4,0) coordinate (-b) --
(0,4) coordinate (-c) -- cycle;
}
]
\coordinate[pin=below:A] (A) at (0,0);
\coordinate[pin=below:B] (B) at (4,0);
\coordinate[pin=C] (C) at (0,4);
%
\pic[above right] at (A) {trian};
\end{tikzpicture}
\end{document}
em ambos os casos o resultado é o mesmo