3

I would like to draw a semi-dashed curved line similar to the line corresponding to \theta_b in the figure below. enter image description here I used the shorten option there which unfortunately modifies the shape of curved lines. What is the easiest way to do that? Here's my full code (the bit corresponding to the curved line is at the end after % temperature values):

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[scale=2]
  % cell dimensions
  \newcommand{\Dx}{3};
  \newcommand{\Dy}{1};
  \newcommand{\Dz}{2};
  % cell vertices
  \coordinate (O) at (0,\Dy,0);
  \coordinate (A) at (0,\Dy,\Dz);
  \coordinate (B) at (\Dx,\Dy,\Dz);
  \coordinate (C) at (\Dx,0,\Dz);
  \coordinate (D) at (0,0,\Dz);
  \coordinate (E) at (\Dx,\Dy,0);
  \coordinate (F) at (\Dx,0,0);
  \coordinate (G) at (0,0,0);
  % cell faces
  \draw[semithick] (A) -- (B) -- (C) -- (D) -- cycle;  % front face
  \draw[semithick] (B) -- (C) -- (F) -- (E) -- cycle;  % left face
  \draw[semithick] (A) -- (B) -- (E) -- (O) -- cycle;  % top face
  % dashed lines
  \coordinate (P) at (0,-0.77,0);  % bottom of back dashed line
  \draw[dashed,color=gray] (D) -- (G);
  \draw[dashed,color=gray] (G) -- (F);
  \draw[dashed,color=gray] (O) -- (G);
  \draw[dashed,color=gray] (G) -- (P);
  % coordinate lines
  \draw[->] (E) -- ++(0.5,0,0) node[anchor=south west] {$x$};
  \draw[->] (A) -- ++(0,0,1) node[anchor=east] {$y$};
  \draw[->] (P) -- ++(0,-0.5,0) node[anchor=north east] {$z$};
  % dimension lines
  \newcommand{\h}{0.2}
  \draw (O) -- ++(0,\h,0);
  \draw (E) -- ++(0,\h,0);
  \draw (A) -- ++(0,\h,0);
  \draw (A) -- ++(-\h,0,0);
  \draw (D) -- ++(-\h,0,0);
  \draw[<->] ($(O)+(0,\h/2,0)$) -- ($(E)+(0,\h/2,0)$) node[midway,above] {$2\pi/a_x$};
  \draw[<->] ($(O)+(0,\h/2,0)$) -- ($(A)+(0,\h/2,0)$) node[xshift=1.5ex, yshift=6.7ex] {$2\pi/a_y$};
  \draw[<->] ($(A)+(-\h/2,0,0)$) -- ($(D)+(-\h/2,0,0)$) node[midway,left] {$d$};
  % temperature values
  \draw (\Dx/2,\Dy,\Dz/2) node {$\theta_s$};
  \filldraw[color=gray] (\Dx/2,0,\Dz/2) circle (0.5pt);
  \draw[dashed,color=gray,shorten >=5]  (0.5*\Dx,0,0.5*\Dz) .. controls (0.6*\Dx,-0.125*\Dy,0.8*\Dz) .. (0.75*\Dx,-0.3*\Dy,1*\Dz);
  \draw[shorten <=25]  (0.5*\Dx,0,0.5*\Dz) .. controls (0.6*\Dx,-0.125*\Dy,0.8*\Dz) .. (0.75*\Dx,-0.3*\Dy,1*\Dz) node[xshift=1.5ex, yshift=-0.7ex] {$\theta_b$};
\end{tikzpicture}
\end{document}
  • 3
    Welcome to TeX.SX! Please add a full mwe starting with \documentclass and ending with \end{document} and not just a fragment. What is wrong with \draw[dashed]? – Bobyandbob May 23 '18 at 9:27
  • Well, I would like the line to be solid once it's "outside" the parallelepiped. Just as it is the case with the z axis. – sleepingrabbit May 23 '18 at 9:56
2

Well, if all you want to do is to have a smooth curve that changes to a dashed pattern inside the box, just draw two curves with the to[in=...,out=...] syntax and make sure that the angles match, i.e. the in of the incoming curve and the out of the outgoing curve have to differ by 180.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[scale=2]
  % cell dimensions
  \newcommand{\Dx}{3};
  \newcommand{\Dy}{1};
  \newcommand{\Dz}{2};
  % cell vertices
  \coordinate (O) at (0,\Dy,0);
  \coordinate (A) at (0,\Dy,\Dz);
  \coordinate (B) at (\Dx,\Dy,\Dz);
  \coordinate (C) at (\Dx,0,\Dz);
  \coordinate (D) at (0,0,\Dz);
  \coordinate (E) at (\Dx,\Dy,0);
  \coordinate (F) at (\Dx,0,0);
  \coordinate (G) at (0,0,0);
  % cell faces
  \draw[semithick] (A) -- (B) -- (C) -- (D) -- cycle;  % front face
  \draw[semithick] (B) -- (C) -- (F) -- (E) -- cycle;  % left face
  \draw[semithick] (A) -- (B) -- (E) -- (O) -- cycle;  % top face
  % dashed lines
  \coordinate (P) at (0,-0.77,0);  % bottom of back dashed line
  \draw[dashed,color=gray] (D) -- (G);
  \draw[dashed,color=gray] (G) -- (F);
  \draw[dashed,color=gray] (O) -- (G);
  \draw[dashed,color=gray] (G) -- (P);
  % coordinate lines
  \draw[->] (E) -- ++(0.5,0,0) node[anchor=south west] {$x$};
  \draw[->] (A) -- ++(0,0,1) node[anchor=east] {$y$};
  \draw[->] (P) -- ++(0,-0.5,0) node[anchor=north east] {$z$};
  % dimension lines
  \newcommand{\h}{0.2}
  \draw (O) -- ++(0,\h,0);
  \draw (E) -- ++(0,\h,0);
  \draw (A) -- ++(0,\h,0);
  \draw (A) -- ++(-\h,0,0);
  \draw (D) -- ++(-\h,0,0);
  \draw[<->] ($(O)+(0,\h/2,0)$) -- ($(E)+(0,\h/2,0)$) node[midway,above] {$2\pi/a_x$};
  \draw[<->] ($(O)+(0,\h/2,0)$) -- ($(A)+(0,\h/2,0)$) node[xshift=1.5ex, yshift=6.7ex] {$2\pi/a_y$};
  \draw[<->] ($(A)+(-\h/2,0,0)$) -- ($(D)+(-\h/2,0,0)$) node[midway,left] {$d$};
  % temperature values
  \draw (\Dx/2,\Dy,\Dz/2) node {$\theta_s$};
  \filldraw[color=gray] (\Dx/2,0,\Dz/2) circle (0.5pt);
   \draw[dashed,color=gray]  (0.66*\Dx,0,\Dz) to[out=110,in=-100] (0.5*\Dx,0,0.5*\Dz);
   \draw  (0.66*\Dx,0,\Dz) 
   to[out=-70,in=135] (0.75*\Dx,-0.3*\Dy,1*\Dz) node[xshift=1.5ex, yshift=-0.7ex] {$\theta_b$};
\end{tikzpicture}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.