0

How to tilt the whole drawing at an angle equal to 30°?

\documentclass[tikz,border=3mm]{standalone}
\usepackage{siunitx} 
\usetikzlibrary{calc,patterns}
\makeatletter
\tikzset{vertical custom shading/.code={%
        \pgfmathsetmacro\tikz@vcs@middle{#1}
        \pgfmathsetmacro\tikz@vcs@bottom{\tikz@vcs@middle/2}
        \pgfmathsetmacro\tikz@vcs@top{(100-\tikz@vcs@middle)/2+\tikz@vcs@middle}
        \pgfdeclareverticalshading[tikz@axis@top,tikz@axis@middle,tikz@axis@bottom]{newaxis}{100bp}{%
            color(0bp)=(tikz@axis@bottom);
            color(\tikz@vcs@bottom bp)=(tikz@axis@bottom);
            color(\tikz@vcs@middle bp)=(tikz@axis@middle);
            color(\tikz@vcs@top bp)=(tikz@axis@top);
            color(100bp)=(tikz@axis@top)}
        \pgfkeysalso{/tikz/shading=newaxis}
    }
}
\makeatother
\begin{document}
    \begin{tikzpicture}[line cap=round,line join=round]

    \begin{scope}[scale=1]  
    \path[bottom color=gray!50!black,top color=gray!10, postaction={pattern=north east lines,rotate=30}] ((0,3) rectangle (5,2.7) (0,3) edge (5,3) ;
    \end{scope}


    \begin{scope}[scale=1,xshift=1cm,yshift=3cm]

    pics/hook/.style={code={
            \pgfgettransformentries{\tmpa}{\tmpb}{\tmpc}{\tmpd}{\tmp}{\tmp}%
            \pgfmathsetmacro{\myJacobian}{sqrt(abs(\tmpa*\tmpd-\tmpb*\tmpc))}  
            \draw[rotate=-90,scale=0.24,yshift=5.2cm,xshift=-3.2cm,double distance=.3mm, double=gray!80,color=black!78,line width=\myJacobian*.7pt,line cap=round]
            (.25,-1.1) -- (.25,-0.8) to[out=90,in=240] (0.6,-0.4)
            arc[start angle=-30,end angle=220,x radius=0.44cm,y radius=0.445cm];}

        \filldraw [scale=1.2,xshift=-.16cm,rounded corners=4pt,left color=black!95,right color=black,middle color=black!70, vertical custom shading=60, shading angle=90] (0,0) -- (1,0) -- (1,1) -- (0,1) -- cycle

        node [inner sep=2pt,rounded corners=1pt,fill=gray!30,
        text=black] at (.5,.5) {{\small M}};},

    \end{scope}
    \end{tikzpicture}
\end{document}

3 Answers 3

2

If you add rotate=30 to the options of the tikzpicture environment then you get:

enter image description here

For completeness, even though I've already descried the change, here is your updated code :

\documentclass[tikz,border=3mm]{standalone}
\usepackage{siunitx}
\usetikzlibrary{calc,patterns}
\makeatletter
\tikzset{vertical custom shading/.code={%
        \pgfmathsetmacro\tikz@vcs@middle{#1}
        \pgfmathsetmacro\tikz@vcs@bottom{\tikz@vcs@middle/2}
        \pgfmathsetmacro\tikz@vcs@top{(100-\tikz@vcs@middle)/2+\tikz@vcs@middle}
        \pgfdeclareverticalshading[tikz@axis@top,tikz@axis@middle,tikz@axis@bottom]{newaxis}{100bp}{%
            color(0bp)=(tikz@axis@bottom);
            color(\tikz@vcs@bottom bp)=(tikz@axis@bottom);
            color(\tikz@vcs@middle bp)=(tikz@axis@middle);
            color(\tikz@vcs@top bp)=(tikz@axis@top);
            color(100bp)=(tikz@axis@top)}
        \pgfkeysalso{/tikz/shading=newaxis}
    }
}
\makeatother
\begin{document}
    \begin{tikzpicture}[line cap=round,line join=round, rotate=30]

    \begin{scope}[scale=1]
    \path[bottom color=gray!50!black,top color=gray!10, postaction={pattern=north east lines,rotate=30}] ((0,3) rectangle (5,2.7) (0,3) edge (5,3) ;
    \end{scope}


    \begin{scope}[scale=1,xshift=1cm,yshift=3cm]

    pics/hook/.style={code={
            \pgfgettransformentries{\tmpa}{\tmpb}{\tmpc}{\tmpd}{\tmp}{\tmp}%
            \pgfmathsetmacro{\myJacobian}{sqrt(abs(\tmpa*\tmpd-\tmpb*\tmpc))}
            \draw[rotate=-90,scale=0.24,yshift=5.2cm,xshift=-3.2cm,double distance=.3mm, double=gray!80,color=black!78,line width=\myJacobian*.7pt,line cap=round]
            (.25,-1.1) -- (.25,-0.8) to[out=90,in=240] (0.6,-0.4)
            arc[start angle=-30,end angle=220,x radius=0.44cm,y radius=0.445cm];}

        \filldraw [scale=1.2,xshift=-.16cm,rounded corners=4pt,left color=black!95,right color=black,middle color=black!70, vertical custom shading=60, shading angle=90] (0,0) -- (1,0) -- (1,1) -- (0,1) -- cycle

        node [inner sep=2pt,rounded corners=1pt,fill=gray!30,
        text=black] at (.5,.5) {{\small M}};},

    \end{scope}
    \end{tikzpicture}
\end{document}
1

This is a partial answer. Rotate it with zero opacity to get the correct bounding box and then use transform canvas to rotate it. The shadings get rotated but not the patterns. You can rotate the patterns with the patterns.meta library, if needed.

\documentclass[tikz,border=3mm]{standalone}
\usepackage{siunitx} 
\usetikzlibrary{calc,patterns}
\makeatletter
\tikzset{vertical custom shading/.code={%
        \pgfmathsetmacro\tikz@vcs@middle{#1}
        \pgfmathsetmacro\tikz@vcs@bottom{\tikz@vcs@middle/2}
        \pgfmathsetmacro\tikz@vcs@top{(100-\tikz@vcs@middle)/2+\tikz@vcs@middle}
        \pgfdeclareverticalshading[tikz@axis@top,tikz@axis@middle,tikz@axis@bottom]{newaxis}{100bp}{%
            color(0bp)=(tikz@axis@bottom);
            color(\tikz@vcs@bottom bp)=(tikz@axis@bottom);
            color(\tikz@vcs@middle bp)=(tikz@axis@middle);
            color(\tikz@vcs@top bp)=(tikz@axis@top);
            color(100bp)=(tikz@axis@top)}
        \pgfkeysalso{/tikz/shading=newaxis}
    }
}
\makeatother
\begin{document}
 \begin{tikzpicture}[line cap=round,line join=round]
  \def\Whatever{\begin{scope}[scale=1]  
    \path[bottom color=gray!50!black,top color=gray!10, postaction={pattern=north east lines,rotate=30}] ((0,3) rectangle (5,2.7) (0,3) edge (5,3) ;
    \end{scope}


    \begin{scope}[scale=1,xshift=1cm,yshift=3cm]
        \filldraw [scale=1.2,xshift=-.16cm,rounded corners=4pt,left color=black!95,right color=black,middle color=black!70, vertical custom shading=60, shading angle=90] (0,0) -- (1,0) -- (1,1) -- (0,1) -- cycle
        node [inner sep=2pt,rounded corners=1pt,fill=gray!30,
        text=black] at (.5,.5) {{\small M}};
    \end{scope}}
   \begin{scope}[opacity=0,rotate=30]
     \Whatever
   \end{scope}
   \begin{scope}[transform canvas={rotate=30}]
     \Whatever
   \end{scope}
 \end{tikzpicture}
\end{document}

enter image description here

2
  • How to rotate pattern.
    – moumou85
    Feb 1, 2020 at 8:38
  • @moumou85 You can do that with patterns.meta, as I wrote.
    – user194703
    Feb 1, 2020 at 15:18
0

I found how to customize pattern using the following code:

Into the preambule:

\tikzdeclarepattern{
    name=hatch,
    parameters={\hatchsize,\hatchangle,\hatchlinewidth},
    bounding box={(-.1pt,-.1pt) and (\hatchsize+.1pt,\hatchsize+.1pt)},
    tile size={(\hatchsize,\hatchsize)},
    tile transformation={rotate=\hatchangle},
    defaults={
        hatch size/.store in=\hatchsize,hatch size=5pt,
        hatch angle/.store in=\hatchangle,hatch angle=0,
        hatch linewidth/.store in=\hatchlinewidth,hatch linewidth=.4pt,
    },
    code={
        \draw[line width=\hatchlinewidth] (0,0) -- (\hatchsize,\hatchsize);
    }
}

and this in document,

\draw [pattern={hatch[hatch size=4pt, hatch linewidth=.4pt, hatch angle=90]}, pattern color=black] [preaction={bottom color=gray!70!black,top color=gray!10}] ((0,3) rectangle (5,2.7) (0,3) edge (5,3) ;

and to rotate I use:

\begin{turn}{angle}
\end{turn}

Thanx all for your answers.

You must log in to answer this question.

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