
Wie kann ich in Tikz ein Raster mit dem „redundanten“ Koordinatensystem (r,g,b) – oder (c,b,a) in der Abbildung – einrichten und dann ein einzelnes Dreieck zeichnen, das durch zwei Koordinaten in einer bestimmten Farbe angegeben wird?
Wie kann ich beispielsweise das Raster in der Abbildung einrichten und dann das Dreieck [r= +2, b= -1] in Orange oder das Dreieck [r= +2, g= -2] in Violett zeichnen?
Antwort1
Sie könnten etwas wie folgt verwenden:
€dit: Dreiecke.
%\documentclass[]{article}
\documentclass[margin=5pt, tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\begin{document}
\pgfmathsetmacro\xMax{8}
\pgfmathsetmacro\yMax{7}
\pgfmathsetmacro\s{2*sqrt(3)/3}
\begin{tikzpicture}[font=\footnotesize,
x={(1,0)}, y={(60:1)},
>=latex,
Point/.style={draw=red, fill=white},
shape triangle/.style = {draw, thick, regular polygon, regular polygon sides=3, minimum height=\s cm, % anchor=center,
inner sep=0pt,
},
triangle/.style={shape triangle, shift={(0.5,0.25*\s cm)}},
triangle*/.style={shape triangle, shape border rotate=180, , shift={(0.5,-0.25*\s cm)}},
]
% Contents
\fill[purple] (0,3) -- (0,4) -- (4,0) -- (3,0) --cycle;
\node[triangle*, fill=green] at (4,4) {$\downarrow$};
\node[triangle, fill=green!77!red] at (4,4) {$\uparrow$};
\node[triangle, fill=red] at (2,5) {a};
\node[triangle, fill=cyan] at (2,3) {};
\node[triangle*, fill=yellow] at (0,7) {};
% CoSy
\begin{scope}[very thin]
\clip[] (0,0) -- (\xMax,0) -- (\xMax cm+\pgflinewidth, \yMax) -- (\pgflinewidth,\yMax) --cycle;
% Contents - cliped
\fill[blue!33, opacity=0.7] (0,1) rectangle (\xMax,2);
\fill[purple!33, opacity=0.7] (6,0) -- (7,0)--(7,8)--(6,8)--cycle;
\foreach \y in {0,...,\yMax}{
\tikzset{ temp/.style={fill=pink, draw=none,opacity=0.1} }
\node[triangle*, temp] at (6,\y) {};
\node[triangle, temp] at (6,\y) {};
}
% CoSy 1/2 - "grid"
\foreach \x in {0,...,\xMax}{
\draw[] (\x,0) -- (\x,\yMax);
}
%
\pgfmathsetmacro\yMAX{2*\yMax}
\foreach \y in {0,...,\yMAX}{
\draw[] (0,\y) -- (\xMax,\y);
\draw[] (0,\y) -- (\y,0);
}
\end{scope}
% CoSy 2/2 - "axes"
\draw[thick,->] (0,0) -- (\xMax+0.5,0) node[below]{$x$};
\draw[thick,->] (0,0) -- (0,\yMax+0.5) node[left]{$y$};
\foreach \x in {0,...,\xMax}{
\draw[] (\x,2pt) -- (\x,-2pt) node[below] {\x};
}
\foreach \y in {0,...,\yMax}{
\draw[] (2pt,\y) -- (-2pt,\y) node[left] {\if\y 0 \else \y\fi};
}
% Contents - Points
\draw[Point, draw=green] (4,4) circle(2pt);
\draw[Point] (0,1) circle(2pt);
\draw[Point] (3,3.5) circle(2pt);
\draw[Point] (4,6) circle(2pt);
\end{tikzpicture}
\end{document}