6

I want to transform the canonical coordinates system , i.e. whose basis vectors are (1,0) and (0,1):

\documentclass[a4paper, 12pt]{report}
\usepackage{fullpage}[1cm]
\usepackage{tikz}
\usepackage{pdfpages}

\begin{document}
\begin{tikzpicture}[scale=3]
\def \xLabel {$X$};
\def \yLabel {$Y$};
\draw[step=.2cm,gray,very thin] (-1.4,-1.4) grid (1.4,1.4);
\draw (-1.5,0) -- (1.5,0);  
\draw (0,-1.5) -- (0,1.5);
\end{tikzpicture}

\end{document}

To a new coordinates system with basis (1,-0.5) and (-0.5,1) (for example)

Many Thanks !!

6

You can redefine the unit vectors using x={(1,-0.5)}, y={(-0.5,1)}. Unfortunately, the grid command doesn't take these unit vectors into account, so you'll have to draw the grid lines "by hand":

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usepackage{pdfpages}

\begin{document}
\begin{tikzpicture}[scale=3, x={(1,-0.5)}, y={(-0.5,1)}]
\def \xLabel {$X$};
\def \yLabel {$Y$};

\begin{scope}{very thin, gray}
\foreach \x in {-1.5,-1,...,1.5}{
    \draw (\x,-1.5) -- (\x,1.5);
}
\foreach \y in {-1.5,-1,...,1.5}{
    \draw (-1.5,\y) -- (1.5,\y);
}
\end{scope}
\draw [very thick, cyan!80!black] (-1.5,0) -- (1.5,0);  
\draw [very thick, cyan!80!black] (0,-1.5) -- (0,1.5);
\end{tikzpicture}

\end{document}
4

You can apply the transformation by using \pgftransformcm command. The grid command works at this condition.

transformation

Code:

\documentclass[border=3mm]{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
    \draw [very thin,gray!40,dashed] (-3,-3) grid (3,3);
    %Specify the transformation matrix and the center point
    \pgftransformcm{1}{-0.5}{-0.5}{1}{\pgfpoint{0}{0}}
    \draw [black!60] (-3,-3) grid (3,3);
    \draw [thick,red,<->] (3.5,0) node [above] {$x$} -- (0,0) -- (0,3.5) node [right] {$y$};
\end{tikzpicture}
\end{document}

Here's another example: Drawing lattice points and vectors

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.