Incomplete \iffalse: How to shift a scope in polar coordinate?

It seems that commands can't be used as option of scope. Try the following:

\documentclass[tikz, margin=3mm]{standalone}
\usepackage{graphicx}
\usepackage{pgf}

\newcommand\object{
    \draw[fill=red] (0,0) rectangle ++(2,2);
}
\tikzset{polarshift/.style args={#1/#2}{xshift=#1*cos(#2),yshift=#1*sin(#2)}}

\begin{document}
    \begin{tikzpicture}
    \object;
    \begin{scope}[polarshift=60/30]
        \object;
    \end{scope}
    \end{tikzpicture}
\end{document}

enter image description here


If I understood your problem correctly, just shift it to a polar coordinate:

\begin{scope}[shift={(30:2)}]

screenshot

\documentclass[tikz]{standalone}
\usepackage{graphicx}
\usepackage{pgf}

\newcommand\object{
    \draw[fill=red] (0,0) rectangle ++(2,2);
}

%\newcommand\polarshift[2]{
%    xshift = \pgfmathparse{multiply(#1,cos(#2))}
%    yshift = \pgfmathparse{multiply(#1,sin(#2))}
%}

\begin{document}
    \begin{tikzpicture}
    \object;
    \begin{scope}[shift={(30:2)}]
        \object;
    \end{scope}
    \end{tikzpicture}
\end{document}

This is an attempt to convince you to make things more TikZy. Instead of a macro \object it is arguably better to define a pic object. Then the shift is just the (relative) coordinate of the pic:

\documentclass[tikz]{standalone}

\begin{document}
\begin{tikzpicture}[pics/object/.style={
    code={\draw[fill=red] (0,0) rectangle ++(2,2);}}]
 \path pic{object} (30:60pt) pic{object} ;
\end{tikzpicture}
\end{document}

enter image description here

As you see, the code becomes much shorter. And it is easier to customize things:

\documentclass[tikz]{standalone}

\begin{document}
\begin{tikzpicture}[pics/object/.style={
    code={\draw[fill=red,pic actions] (0,0) rectangle ++(2,2);}}]
 \path pic{object} (30:60pt) pic[rotate=30,scale=1.2,dashed,draw=blue]{object} ;
\end{tikzpicture}
\end{document}

enter image description here

ADDENDUM: as for your comment: of course, your approach can be made work, too. First of all, TikZ automatically parses these expressions, so there is no need to say \pgfmathparse. Other than that you are missing a comma, and you need to expand the macro.

\documentclass[tikz]{standalone}
%\usepackage{graphicx} %<-loaded by tikz
%\usepackage{pgf}% <- loaded by tikz

\newcommand\object{
    \draw[fill=red] (0,0) rectangle ++(2,2);
}

\newcommand\polarshift[2]{
    xshift ={#1*cos(#2)},
    yshift ={#1*sin(#2)}
}

\begin{document}
    \begin{tikzpicture}
    \object;
    \begin{scope}[style/.expanded=\polarshift{60}{30}]
        \object;
    \end{scope}
    \end{tikzpicture}
\end{document}

enter image description here

Tags:

Tikz Pgf