2

I want to modify the hatch lines direction marked in red of the next diagram:

enter image description here

It was obtained with the next code:

\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}

I want to change the hatch lines to something like "custom east lines", that is this direction . Any help is appreciated.

Alfredo
  • 363

1 Answers1

1

This comes with a pattern custom horizontal lines that is an analog of your pattern custom north west lines. I also simplified the upper part of your code by switching to 3d coordinates.

\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}

enter image description here

custom north east lines are even simple because you only need to exchange two coordinates.

\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}

enter image description here

  • Hello @marmot, I made a mistake. With the code I wrote I get a different diagonal hatching. I want to get the kind of diagonal hatching that I have posted in the figure. It is diagonal lines "/". Sorry for the confusions. – Alfredo Apr 07 '19 at 14:45
  • @Alfredo You already got the diagonal hatching in the code of your question. What is your question then about, i.e. what do you want us to do? –  Apr 07 '19 at 14:47
  • if you run my code you get a different hatch that is in the figure. Watch it carefully, is not the same. The question is: How can I obtain that hatch of the figure?. – Alfredo Apr 07 '19 at 14:52
  • @Alfredo I see. I added custom north east lines. BTW, if you got custom north west lines from some other post, could you perhaps consider indicating the source? Whoever wrote this pattern deserves some credit, I think. –  Apr 07 '19 at 15:02
  • 1
    the custom north west lines code was obtained from the answer of @Alain Matthes here: https://tex.stackexchange.com/questions/54464/hatch-a-rectangle-in-tikz/54465 – Alfredo Apr 07 '19 at 15:12