我想修改下图中红色标记的阴影线方向:
它是通过以下代码获得的:
\documentclass[letterpaper,11pt]{report}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{float}
\usepackage[none]{hyphenat}
\usepackage{array}
\usepackage{graphicx}
\usepackage{pgfplots}
\pgfplotsset{width=15cm,compat=1.9}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{patterns,arrows,fit,matrix,arrows.meta,calc,decorations.pathmorphing,decorations.markings,decorations.pathreplacing}
\usepackage{tikz}
\usepackage{bigstrut}
\usepackage{float}
\usepackage{bbding}
\usepackage{diagbox}
\usepackage{scalerel}
\let\savestar\star
\renewcommand\star{{\scalerel*{\bigstar}{\savestar}}}
\allowdisplaybreaks
\usepackage[resetlabels,labeled]{multibib}
\usepackage{url}
\usepackage{subcaption}
\usepackage{cite}
\usepackage{multirow}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{ltablex}
\usepackage{mathrsfs}
\usepackage{rsfso}
\usepackage{booktabs}
\usepackage{mathtools}
% defining the new dimensions and parameters
\newlength{\hatchspread}
\newlength{\hatchthickness}
\newlength{\hatchshift}
\newcommand{\hatchcolor}{}
% declaring the keys in tikz
\tikzset{hatchspread/.code={\setlength{\hatchspread}{#1}},
hatchthickness/.code={\setlength{\hatchthickness}{#1}},
hatchshift/.code={\setlength{\hatchshift}{#1}},% must be >= 0
hatchcolor/.code={\renewcommand{\hatchcolor}{#1}}}
% setting the default values
\tikzset{hatchspread=5pt,
hatchthickness=0.4pt,
hatchshift=1.5pt,% must be >= 0
hatchcolor=black}
% declaring the pattern
\pgfdeclarepatternformonly[\hatchspread,\hatchthickness,\hatchshift,\hatchcolor]% variables
{custom north west lines}% name
{\pgfqpoint{\dimexpr-2\hatchthickness}{\dimexpr-2\hatchthickness}}% lower left corner
{\pgfqpoint{\dimexpr\hatchspread+2\hatchthickness}{\dimexpr\hatchspread+2\hatchthickness}}% upper right corner
{\pgfqpoint{\dimexpr\hatchspread}{\dimexpr\hatchspread}}% tile size
{% shape description
\pgfsetlinewidth{\hatchthickness}
\pgfpathmoveto{\pgfqpoint{0pt}{\dimexpr\hatchspread+\hatchshift}}
\pgfpathlineto{\pgfqpoint{\dimexpr\hatchspread+0.15pt+\hatchshift}{-0.15pt}}
\ifdim \hatchshift > 0pt
\pgfpathmoveto{\pgfqpoint{0pt}{\hatchshift}}
\pgfpathlineto{\pgfqpoint{\dimexpr0.15pt+\hatchshift}{-0.15pt}}
\fi
\pgfsetstrokecolor{\hatchcolor}
% \pgfsetdash{{1pt}{1pt}}{0pt}% dashing cannot work correctly in all situation this way
\pgfusepath{stroke}
}
\begin{document}
\begin{figure}[ht]
\centering
\begin{tikzpicture}
\draw (0,0) ellipse (5.375cm and 1.5cm);
\draw (-5.375,-0.5) arc (180:360:5.375 and 1.5);
\draw (-5.375,0) -- ++(0,-0.5);
\draw (5.375,0) -- ++(0,-0.5);
\draw (0,0) ellipse (2.685cm and 0.75cm);
\draw (2.6,-0.2) arc (19:165:2.7 and 0.75);
\draw (1.5,0) -- (2.7,0);
\draw (-2.7,0) -- (-1.5,0);
\draw (0,0.75) -- (0,0.2);
\draw (0,-0.75) -- (0,-0.2);
\draw (1.7,0.6) -- (0.7,0.2);
\draw (1.7,-0.6) -- (0.7,-0.2);
\draw (-1.7,0.6) -- (-0.7,0.2);
\draw (-1.7,-0.6) -- (-0.7,-0.2);
\draw (0.8,0.7) -- (0.35,0.2);
\draw (0.8,-0.7) -- (0.35,-0.2);
\draw (-0.8,0.7) -- (-0.35,0.2);
\draw (-0.8,-0.7) -- (-0.35,-0.2);
\draw (2.4,0.3) -- (1.2,0.1);
\draw (2.4,-0.3) -- (1.2,-0.1);
\draw (-2.4,0.3) -- (-1.2,0.1);
\draw (-2.4,-0.3) -- (-1.2,-0.1);
\path (0,-7) -- (5,-7) node[inner sep=2pt,circle,fill,pos=0] (x1) {};
\draw[-{Latex[length=2mm]}] (0,-7) -- (6,-7) node[pos=1.1,fill=white,circle]{$r$};
\draw[-{Latex[length=2mm]}] (0,-7) -- (0,-13) node[pos=1.1,circle]{$z(r,\theta)$};
\draw (2.685,-6.7) -- (5.375,-6.7) -- (5.375,-7.3) -- (2.685,-7.3) -- (2.685,-6.7);
\draw (-2.685,-6.7) -- (-5.375,-6.7) -- (-5.375,-7.3) -- (-2.685,-7.3) -- (-2.685,-6.7);
\draw (2.685,-5.3) -- (2.685,-8.7); % línea para ashurado
\draw (-2.685,-5.3) -- (-2.685,-8.7);
\draw (2.685,-9.3) -- (2.685,-10.7);%Linea auxiliar 1
\draw (-5.375,-10.3) -- (-5.375,-11.3); % Linea auxiliar 2
\draw[{Latex[length=2mm]}-{Latex[length=2mm]}] (0,-10.1) -- (2.685,-10.1) node[above,pos=0.5,fill=white,circle]{$b$};% Cota 1
\draw[{Latex[length=2mm]}-{Latex[length=2mm]}] (0,-10.8) -- (-5.375,-10.8) node[above,pos=0.5,fill=white,circle]{$a$};% Cota 2
\draw[dashed] (-2.685,-2.3) -- (-2.685,-4.7);
\draw[dashed] (2.685,-2.3) -- (2.685,-4.7);
\draw[dashed] (-5.375,-1.5) -- (-5.375,-5.9);
\draw[dashed] (5.375,-1.5) -- (5.375,-5.9);
\draw[pattern=custom north west lines, hatchspread=24pt, hatchcolor=black, draw=none] (2.1,-8.7) rectangle (2.685,-5.3);
\draw[pattern=custom north west lines,hatchspread=25pt,hatchcolor=black,draw=none] (-2.1,-8.7) rectangle (-2.685,-5.3);
\draw[dashed] (-5.375,-8.1) -- (-5.375,-9.6);
\end{tikzpicture}
\end{figure}
\end{document}
我想将图案线改为“自定义东线”之类的,就是这个方向。如能得到任何帮助,我将不胜感激。
答案1
custom horizontal lines
这带有与您的模式类似的模式custom north west lines
。我还通过切换到 3d 坐标简化了代码的上半部分。
\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{patterns,arrows.meta,3d}
% based on https://tex.stackexchange.com/questions/54464/hatch-a-rectangle-in-tikz/54465
% defining the new dimensions and parameters
\newlength{\hatchspread}
\newlength{\hatchthickness}
\newlength{\hatchshift}
\newcommand{\hatchcolor}{}
% declaring the keys in tikz
\tikzset{hatchspread/.code={\setlength{\hatchspread}{#1}},
hatchthickness/.code={\setlength{\hatchthickness}{#1}},
hatchshift/.code={\setlength{\hatchshift}{#1}},% must be >= 0
hatchcolor/.code={\renewcommand{\hatchcolor}{#1}}}
% setting the default values
\tikzset{hatchspread=5pt,
hatchthickness=0.4pt,
hatchshift=1.5pt,% must be >= 0
hatchcolor=black}
% declaring the pattern
\pgfdeclarepatternformonly[\hatchspread,\hatchthickness,\hatchshift,\hatchcolor]% variables
{custom horizontal lines}% name
{\pgfqpoint{\dimexpr-2\hatchthickness}{\dimexpr-2\hatchthickness}}% lower left corner
{\pgfqpoint{\dimexpr\hatchspread+2\hatchthickness}{\dimexpr\hatchspread+2\hatchthickness}}% upper right corner
{\pgfqpoint{\dimexpr\hatchspread}{\dimexpr\hatchspread}}% tile size
{% shape description
\pgfsetlinewidth{\hatchthickness}
\pgfpathmoveto{\pgfqpoint{0pt}{\dimexpr 0.5\hatchspread+\hatchshift}}
\pgfpathlineto{\pgfqpoint{\dimexpr\hatchspread+0.15pt+\hatchshift}{\dimexpr 0.5\hatchspread+\hatchshift}}
\pgfsetstrokecolor{\hatchcolor}
% \pgfsetdash{{1pt}{1pt}}{0pt}% dashing cannot work correctly in all situation this way
\pgfusepath{stroke}
}
\begin{document}
\begin{tikzpicture}
\tdplotsetmaincoords{74}{0}
\begin{scope}[tdplot_main_coords,canvas is xy plane at z=0,transform shape]
\draw (0,0) circle[radius=5.375cm];
\draw (-5.375,0) -- (-5.375,-1.8)
arc(180:360:5.375cm) --(5.375,0);
\draw[clip] (0,0) circle[radius=2.685cm];
\draw (0,-1.6) circle[radius=2.685cm];
\foreach \X in {0,22.5,...,337.5}
{\draw (\X:2.685) -- (\X:1);}
\end{scope}
\path (0,-7) -- (5,-7) node[inner sep=2pt,circle,fill,pos=0] (x1) {};
\draw[-{Latex[length=2mm]}] (0,-7) -- (6,-7) node[pos=1.1,fill=white,circle]{$r$};
\draw[-{Latex[length=2mm]}] (0,-7) -- (0,-13) node[pos=1.1,circle]{$z(r,\theta)$};
\draw (2.685,-6.7) -- (5.375,-6.7) -- (5.375,-7.3) -- (2.685,-7.3) -- (2.685,-6.7);
\draw (-2.685,-6.7) -- (-5.375,-6.7) -- (-5.375,-7.3) -- (-2.685,-7.3) -- (-2.685,-6.7);
\draw (2.685,-5.3) -- (2.685,-8.7); % línea para ashurado
\draw (-2.685,-5.3) -- (-2.685,-8.7);
\draw (2.685,-9.3) -- (2.685,-10.7);%Linea auxiliar 1
\draw (-5.375,-10.3) -- (-5.375,-11.3); % Linea auxiliar 2
\draw[{Latex[length=2mm]}-{Latex[length=2mm]}] (0,-10.1) -- (2.685,-10.1) node[above,pos=0.5,fill=white,circle]{$b$};% Cota 1
\draw[{Latex[length=2mm]}-{Latex[length=2mm]}] (0,-10.8) -- (-5.375,-10.8) node[above,pos=0.5,fill=white,circle]{$a$};% Cota 2
\draw[dashed] (-2.685,-2.3) -- (-2.685,-4.7);
\draw[dashed] (2.685,-2.3) -- (2.685,-4.7);
\draw[dashed] (-5.375,-1.5) -- (-5.375,-5.9);
\draw[dashed] (5.375,-1.5) -- (5.375,-5.9);
\path[pattern=custom horizontal lines, hatchspread=8pt, hatchcolor=black] (2.1,-8.7) rectangle (2.685,-5.3);
\path[pattern=custom horizontal lines,hatchspread=8pt,hatchcolor=black] (-2.1,-8.7) rectangle (-2.685,-5.3);
\draw[dashed] (-5.375,-8.1) -- (-5.375,-9.6);
\end{tikzpicture}
\end{document}
custom north east lines
甚至很简单,因为您只需要交换两个坐标。
\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{patterns,arrows.meta,3d}
% based on https://tex.stackexchange.com/questions/54464/hatch-a-rectangle-in-tikz/54465
% defining the new dimensions and parameters
\newlength{\hatchspread}
\newlength{\hatchthickness}
\newlength{\hatchshift}
\newcommand{\hatchcolor}{}
% declaring the keys in tikz
\tikzset{hatchspread/.code={\setlength{\hatchspread}{#1}},
hatchthickness/.code={\setlength{\hatchthickness}{#1}},
hatchshift/.code={\setlength{\hatchshift}{#1}},% must be >= 0
hatchcolor/.code={\renewcommand{\hatchcolor}{#1}}}
% setting the default values
\tikzset{hatchspread=5pt,
hatchthickness=0.4pt,
hatchshift=1.5pt,% must be >= 0
hatchcolor=black}
% declaring the pattern
\pgfdeclarepatternformonly[\hatchspread,\hatchthickness,\hatchshift,\hatchcolor]% variables
{custom north east lines}% name
{\pgfqpoint{\dimexpr-2\hatchthickness}{\dimexpr-2\hatchthickness}}% lower left corner
{\pgfqpoint{\dimexpr\hatchspread+2\hatchthickness}{\dimexpr\hatchspread+2\hatchthickness}}% upper right corner
{\pgfqpoint{\dimexpr\hatchspread}{\dimexpr\hatchspread}}% tile size
{% shape description
\pgfsetlinewidth{\hatchthickness}
\pgfpathmoveto{\pgfqpoint{0pt}{-0.15pt}}
\pgfpathlineto{\pgfqpoint{\dimexpr\hatchspread+0.15pt+\hatchshift}{\dimexpr\hatchspread+\hatchshift}}
\ifdim \hatchshift > 0pt
\pgfpathmoveto{\pgfqpoint{0pt}{-0.15pt}}
\pgfpathlineto{\pgfqpoint{\dimexpr0.15pt+\hatchshift}{\hatchshift}}
\fi
\pgfsetstrokecolor{\hatchcolor}
% \pgfsetdash{{1pt}{1pt}}{0pt}% dashing cannot work correctly in all situation this way
\pgfusepath{stroke}
}
% horizontal lines
\pgfdeclarepatternformonly[\hatchspread,\hatchthickness,\hatchshift,\hatchcolor]% variables
{custom horizontal lines}% name
{\pgfqpoint{\dimexpr-2\hatchthickness}{\dimexpr-2\hatchthickness}}% lower left corner
{\pgfqpoint{\dimexpr\hatchspread+2\hatchthickness}{\dimexpr\hatchspread+2\hatchthickness}}% upper right corner
{\pgfqpoint{\dimexpr\hatchspread}{\dimexpr\hatchspread}}% tile size
{% shape description
\pgfsetlinewidth{\hatchthickness}
\pgfpathmoveto{\pgfqpoint{0pt}{\dimexpr 0.5\hatchspread+\hatchshift}}
\pgfpathlineto{\pgfqpoint{\dimexpr\hatchspread+0.15pt+\hatchshift}{\dimexpr 0.5\hatchspread+\hatchshift}}
\pgfsetstrokecolor{\hatchcolor}
% \pgfsetdash{{1pt}{1pt}}{0pt}% dashing cannot work correctly in all situation this way
\pgfusepath{stroke}
}
\begin{document}
\begin{tikzpicture}
\tdplotsetmaincoords{74}{0}
\begin{scope}[tdplot_main_coords,canvas is xy plane at z=0,transform shape]
\draw (0,0) circle[radius=5.375cm];
\draw (-5.375,0) -- (-5.375,-1.8)
arc(180:360:5.375cm) --(5.375,0);
\draw[clip] (0,0) circle[radius=2.685cm];
\draw (0,-1.6) circle[radius=2.685cm];
\foreach \X in {0,22.5,...,337.5}
{\draw (\X:2.685) -- (\X:1);}
\end{scope}
\path (0,-7) -- (5,-7) node[inner sep=2pt,circle,fill,pos=0] (x1) {};
\draw[-{Latex[length=2mm]}] (0,-7) -- (6,-7) node[pos=1.1,fill=white,circle]{$r$};
\draw[-{Latex[length=2mm]}] (0,-7) -- (0,-13) node[pos=1.1,circle]{$z(r,\theta)$};
\draw (2.685,-6.7) -- (5.375,-6.7) -- (5.375,-7.3) -- (2.685,-7.3) -- (2.685,-6.7);
\draw (-2.685,-6.7) -- (-5.375,-6.7) -- (-5.375,-7.3) -- (-2.685,-7.3) -- (-2.685,-6.7);
\draw (2.685,-5.3) -- (2.685,-8.7); % línea para ashurado
\draw (-2.685,-5.3) -- (-2.685,-8.7);
\draw (2.685,-9.3) -- (2.685,-10.7);%Linea auxiliar 1
\draw (-5.375,-10.3) -- (-5.375,-11.3); % Linea auxiliar 2
\draw[{Latex[length=2mm]}-{Latex[length=2mm]}] (0,-10.1) -- (2.685,-10.1) node[above,pos=0.5,fill=white,circle]{$b$};% Cota 1
\draw[{Latex[length=2mm]}-{Latex[length=2mm]}] (0,-10.8) -- (-5.375,-10.8) node[above,pos=0.5,fill=white,circle]{$a$};% Cota 2
\draw[dashed] (-2.685,-2.3) -- (-2.685,-4.7);
\draw[dashed] (2.685,-2.3) -- (2.685,-4.7);
\draw[dashed] (-5.375,-1.5) -- (-5.375,-5.9);
\draw[dashed] (5.375,-1.5) -- (5.375,-5.9);
\path[pattern=custom north east lines, hatchspread=10pt, hatchcolor=black] (2.1,-8.7) rectangle (2.685,-5.3);
\path[pattern=custom north east lines,hatchspread=10pt,hatchcolor=black] (-2.1,-8.7) rectangle (-2.685,-5.3);
\draw[dashed] (-5.375,-8.1) -- (-5.375,-9.6);
\end{tikzpicture}
\end{document}