如何将整个绘图倾斜 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}
答案1
如果你添加rotate=30
环境选项,tikzpicture
那么你将获得:
为了完整起见,尽管我已经描述了变化,但这里是您的更新代码:
\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}
答案2
这是部分答案。用零不透明度旋转它以获得正确的边界框,然后使用它transform canvas
来旋转它。阴影会旋转,但图案不会。patterns.meta
如果需要,您可以使用库旋转图案。
\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}
答案3
我发现如何使用以下代码自定义模式:
进入序言:
\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);
}
}
这是文档中的内容,
\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) ;
旋转我用的是:
\begin{turn}{angle}
\end{turn}
谢谢大家的回答。