I am trying to adjust the unit vectors for each of the axis, and draw a coordinate grid. I can get it to work without specifying the unit vectors, of specifying it as:
x={(1.0cm,0.0cm)}, y={(0.0cm,1.0cm), z={(-0.5cm,-0.1cm)}
Since I don't notice any difference in the output I am assuming that the above are the default settings. The above yields the graph on the left, but if I specify
x={(-0.5cm,-0.5cm)}, y={(0.9659cm,-0.25882cm)}, z={(0cm,1cm)}
then I get the grid on the right where the x-y
grid (in red) does not quite look right to me.
The triangle in yellow is to show that the coordinates are working fine as it is drawn as:
\begin{scope}[canvas is xy plane at z=0]
\draw [fill=yellow!10,opacity=0.2] (0,1) -- (3,0) -- (0,4) -- cycle;
\end{scope}
References:
- A very good reference for the unit vectors is available at Drawing simple 3D cylinders in TikZ
- The settings for the unit vectors that I am trying to use are from the 3d box example from altermundus.com
Code:
\documentclass{standalone}
\usepackage{xparse}
\usepackage{tikz}
\usetikzlibrary{3d}
\NewDocumentCommand{\DrawCoordinateGrid}{O{} m m m m m m}{%
\def\XGridMin{#2}
\def\XGridMax{#3}
\def\YGridMin{#4}
\def\YGridMax{#5}
\def\ZGridMin{#6}
\def\ZGridMax{#7}
%
\begin{scope}[canvas is xy plane at z=0, thick, red]
\draw [#1] (\XGridMin,\YGridMin) grid (\XGridMax,\YGridMax);
\end{scope}
\begin{scope}[canvas is yz plane at x=0, thin, blue]
\draw [#1] (\YGridMin,\ZGridMin) grid (\YGridMax,\ZGridMax);
\end{scope}
\begin{scope}[canvas is xz plane at y=0, thin, orange]
\draw [#1] (\XGridMin,\ZGridMin) grid (\XGridMax,\ZGridMax);
\end{scope}
}%
\NewDocumentCommand{\DrawCoordinateAxis}{O{} m m m m m m}{%
\def\XAxisMin{#2}
\def\XAxisMax{#3}
\def\YAxisMin{#4}
\def\YAxisMax{#5}
\def\ZAxisMin{#6}
\def\ZAxisMax{#7}
%
\begin{scope}[thin, gray, -latex]
\draw [#1] (\XAxisMin,0,0) -- (\XAxisMax,0,0) node [below left] {$x$};
\draw [#1] (0,\YAxisMin,0) -- (0,\YAxisMax,0) node [right] {$y$};
\draw [#1] (0,0,\ZAxisMin) -- (0,0,\ZAxisMax) node [above] {$z$};
\end{scope}
}%
% A macro to save repeating the code
\newcommand*{\DrawTriangle}{%
\begin{scope}[canvas is xy plane at z=0]
\draw [fill=yellow!10,opacity=0.2] (0,1) -- (3,0) -- (0,4) -- cycle;
\end{scope}
}%
\begin{document}
\begin{tikzpicture}[
x={(1.0cm,0.0cm)}, y={(0.0cm,1.0cm), z={(-0.5cm,-0.1cm)}}% All grids are ok
]
\DrawCoordinateGrid{0}{4}{0}{4}{0}{4}
\DrawCoordinateAxis[thick, black]{0}{5}{0}{5}{0}{5}
\DrawTriangle;% For reference purposes
\end{tikzpicture}
%
\begin{tikzpicture}[
x={(-0.5cm,-0.5cm)}, y={(0.9659cm,-0.25882cm)}, z={(0cm,1cm)}% x-y grid is wacky
]
\DrawCoordinateGrid{0}{4}{0}{4}{0}{4}
\DrawCoordinateAxis[thick, black]{0}{5}{0}{5}{0}{5}
\DrawTriangle;% For reference purposes
\end{tikzpicture}
\end{document}