1

In a thread someone uses the option "cm" as shown in the following shortened example:

Code

\documentclass[12pt,tikz]{standalone}
\begin{document}
\begin{tikzpicture}
  \pgfmathsetmacro{\mySqrt}{sqrt(3)/2}
  \def\r{1}
  \def\a{1}
  \draw [cm={\r,0,.5*\r,\mySqrt*\r,(0,0)}] 
    (1+\a,0) coordinate (-corner 0) coordinate (-corner 3) 
    -- (\a,1) coordinate (-corner 1)
    -- (-\a,1) coordinate (-corner 2)
    -- cycle;
\end{tikzpicture}
\end{document}

From the thread: Scaling only a portion of a TikZ polygon (@marsupilam)

Output

Codeoutput

Question

What does this option do and what mean the parameters?

2
  • 1
    It’s one of the coordinate transformations (see Tikz manual on the p. 379)
    – Celdor
    Commented Mar 31, 2022 at 8:42
  • @Celdor Thank you very much!
    – GURKE
    Commented Mar 31, 2022 at 8:45

2 Answers 2

2

Sometimes we need to use specific geometric transformations. See pgfmanual, Section 25.3 Coordinate Transformations, page 378 for the commands cm and reset cm:

enter image description here

A bit explanation:

  • scale=2 is the same as cm={2, 0, 0, 2, (0,0)}
  • xscale=2 is the same as cm={2, 0, 0, 1, (0,0)}
  • yscale=3 is the same as cm={1, 0, 0, 3, (0,0)}
  • shift={(3,4)} is the same as cm={1, 0, 0, 1, (3,4)}
  • xshift=5cm is the same as cm={1, 0, 0, 1, (5,0)}
  • yshift=6cm is the same as cm={1, 0, 0, 1, (0,6)}
  • xslant=1.5 is the same as cm={1, 0, 1.5, 1, (0,0)}
  • yslant=3 is the same as cm={1, 3, 0, 1, (0,0)}

The following is a small self-tutorial ^^

enter image description here

enter image description here

enter image description here

\documentclass[tikz,border=5mm]{standalone}
\usepackage{amsmath}
\begin{document}
\begin{tikzpicture}[very thick]
\draw[gray!20,thin] (-3,-3) grid (3,3);
\draw[->,gray,thin] (-3.5,0)--(3.5,0) node[below right,black]{$x$}; 
\draw[->,gray,thin] (0,-3.5)--(0,3.5) node[below left,black]{$y$};
\def\mypath{(0,0) rectangle (1,1)}
%\def\mypath{(0,0) circle(1)}
%\def\mypath{(0,0) parabola (2,2)}
%\def\mypath{(0,0) sin (2,1.5)}
%\def\mypath{(0,0) .. controls +(70:2) and +(-100:1) .. (3,2)}


\draw[blue] \mypath;

% [xscale=-3,yscale=-2,shift={(0,-1)}] is the same as cm={-3, 0, 0, -2, (0,-1)}
\draw[cm={-3, 0, 0, -2, (0,-1)},red] \mypath;

% [xslant=1.5] is the same as [cm={1, 0, 1.5, 1, (0,0)}]
\draw[cm={1, 0, 1.5, 1, (0,0)},cyan] \mypath;

\draw[cm={1, 2, 3, -4, (-3,1)},orange] \mypath;

\path (0,4.5) node[align=center]{
\verb|[cm={a, b, c, d, (t_x, t_y)}]|\\[2mm]
$\begin{pmatrix}a&c\\b&d\end{pmatrix}
\begin{pmatrix}x\\y\end{pmatrix}+
\begin{pmatrix}t_x\\t_y\end{pmatrix}$
};
\end{tikzpicture}
\end{document}
2

As @Celdor mentioned, it is just a coordinate transformation.

Having

\draw[cm={a, b, c, d, (t_x, t_y)}] (0,0) -- (1,1) -- (1,0);

every point is transformed by the formula:

enter image description here

where the point is given by x and y.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .