Graphics, Figures & TablestikZ | Interface between Surfaces

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
psionman
Posts: 30
Joined: Thu Nov 10, 2011 3:33 pm

tikZ | Interface between Surfaces

Post by psionman »

I would like to represent the interface between surfaces as a 'hatched' line.

The following code works but it looks wrong at the ends.

Code: Select all

[
  interface/.style={
    postaction={
      draw,
      decorate,
      decoration={
        border,
        angle=45,
        amplitude=0.3cm,
        segment length=3mm
      }
    }
  },
]
The ideal would be a rectangle filled with 'hatches'. The following works, but it slows down the compile drastically (because of the loop?)

Code: Select all

\tikzset{mystripes dist/.initial=0.2}
\pgfdeclarepatternformonly[/tikz/mystripes dist]{mystripes}
{\pgfpointorigin}{\pgfpoint{1cm}{1cm}}
{\pgfpoint{1cm}{1cm}}
{
  \foreach \x in {0,\pgfkeysvalueof{/tikz/mystripes dist},...,1}{
    \pgfmathsetmacro{\nx}{1-\x}
    \tikz[overlay]\draw[decoration = {random steps, segment length = 0.2mm, amplitude = 0.15pt}, decorate] (\x, 0) -- ++(\nx,\nx);
    \tikz[overlay]\draw[decoration = {random steps, segment length = 0.2mm, amplitude = 0.15pt}, decorate] (0, \x) -- ++(\nx,\nx);
  }
}
What can I do?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

tikZ | Interface between Surfaces

Post by localghost »

psionman wrote:[…] What can I do?
As always, start with providing a minimal example to give an adequate problem description.


Thorsten
psionman
Posts: 30
Joined: Thu Nov 10, 2011 3:33 pm

tikZ | Interface between Surfaces

Post by psionman »

Here is the document

It includes two problems:

1. slow compile if multiple

Code: Select all

\filldraw[draw=white,color=black, pattern=mystripes]


are used.

2. I do not want the box around the rectangle

Code: Select all

\documentclass[11pt]{article}

\usepackage{tikz}
\usetikzlibrary{%
    decorations.pathreplacing,%
    decorations.pathmorphing,%
	patterns%
}

\begin{document}
\tikzset{mystripes dist/.initial=0.2}
\pgfdeclarepatternformonly[/tikz/mystripes dist]{mystripes}
{\pgfpointorigin}{\pgfpoint{1cm}{1cm}}
{\pgfpoint{1cm}{1cm}}
{
  \foreach \x in {0,\pgfkeysvalueof{/tikz/mystripes dist},...,1}{
    \pgfmathsetmacro{\nx}{1-\x}
    \tikz[overlay]\draw[decoration = {random steps, segment length = 0.2mm, amplitude = 0.15pt}, decorate] (\x, 0) -- ++(\nx,\nx);
    \tikz[overlay]\draw[decoration = {random steps, segment length = 0.2mm, amplitude = 0.15pt}, decorate] (0, \x) -- ++(\nx,\nx);
  }
}

\begin{figure}[ht]
\begin {center}
\begin{tikzpicture}
[
interfacetop/.style={
        postaction={draw,decorate,decoration={border,angle=135,
                    amplitude=0.4cm,segment length=2mm}}},
]

\coordinate (AL) at (0,8);
\coordinate (AR) at (3,8);
\coordinate (BL) at (0,7);
\coordinate (BR) at (4,7);
\draw[interfacetop](AL)--(AR);


\draw (BL)--(BR);
\filldraw[draw=white,color=black, pattern=mystripes] (BL)   rectangle (3,7.4);
\end{tikzpicture}
\end{center}
\end{figure}

\end{document}
hugovdberg
Posts: 133
Joined: Sat Feb 25, 2012 6:12 pm

tikZ | Interface between Surfaces

Post by hugovdberg »

You might want to take al look at the answers on {TeX} SE seems a pretty solution to me. If you don't want the ticks to extend beyond the ends of the straight line you could throw in a 'pre length' or 'post length' which creates an offset for the decoration.
Ubuntu 13.10 + Tex Live 2013 + Texmaker / Windows 7 Pro + MikTex 2.9 + TexnicCenter / Android 4.3 + TexPortal + DroidEdit
psionman
Posts: 30
Joined: Thu Nov 10, 2011 3:33 pm

Re: tikZ | Interface between Surfaces

Post by psionman »

Thanks hugovdberg. That's a useful link. It's doing more or less what my 'interface' style does. It is acceptable, but not ideal. You're right, the problem occurs at the ends of the line. At one end the sloping line extends beyond the length of the base, and at the other, there should (or could) be shorter, partial sloping lines to fill the space.
Post Reply