Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to draw the "coiled snake " around the rectangle named "Obstacle". The rectangle consist of node "O". I could not figure it out as I am new to tikz. can anyone give me good suggestion in this? Thanks in Advance

Here is the code

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{snakes}
\begin{document}

\begin{tikzpicture}
\tikzstyle{block} = [draw,rounded corners,thin,fill= gray!20,  rectangle,   thick,align=center]
 % Draw axes
 % \node (0,0)(a) {$\theta$}
 \draw [<->,thick] (0,2) node (yaxis) [above] {$y$}
    |- (2,0) node (xaxis) [right] {$x$};
%\draw [gray](0,0)+(0.5,0)arc(0:45:0.5); 
%\path (0,0)++ (22.5:0.7)node{$\theta$};
% Draw two intersecting lines

 \draw (1.2,1.2)coordinate(a_2);
%Draw vehicle
\draw [rotate =20](a_2)+(0.5,0)coordinate(V_c)node[block,minimum width=28,minimum height=18, rotate=20](a){};
\draw[snake=coil,](a)++(45:3)node[block,rotate=45,segment aspect=10,,minimum height=50,font =\large](O){Obstacle};

%Draw body axis
 \draw [->,rotate =20,thick] (V_c) -- ++(0,0.7)node[rotate=20](yaxis)[above]{$y_{b}$};
% \draw [->,rotate =45,thick] (V_c)++(-0.22,0.5) -- ++(0,0.7)node[rotate=45](yaxis)[above]{$v_{y}$};
  \draw [->,rotate =20,thick] (V_c) -- ++(0.8,0)node[rotate=20](yaxis)[below]{$x_{b}$};
  %draw Dimension of distance to obstacle
  \draw[dashed,rotate=45] (a.22) -- (O);
  \draw[snake=brace,raise snake=2pt,gap around snake =2pt,rotate=45] (a.22) -- (O);%for curly bracket
  \path (V_c)+(0.5,0)--coordinate(L)(O);
  \draw [rotate =45] (L)+(0.1,0.5) node[rotate=45]{$L_i$};
  \draw[->](a.10)--+(45:0.5)node[rotate=45,below]{$v$};
 \end{tikzpicture}
  \end{document}
share|improve this question
add comment

1 Answer

up vote 6 down vote accepted

Generally, for these purposes it is necessary to use the so called late options (see 16.14 Late Code and Late Options on the pgfmanual). This is a proof of concept exploiting append after command:

\documentclass[border=10pt,tikz,png]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}

\tikzset{block/.style={draw,rounded corners,thin,fill= gray!20,rectangle,thick,align=center}}
\tikzset{decorate this node/.style={
    append after command={
      \pgfextra{
        \draw[decoration type,decorate,#1](\tikzlastnode.south west)rectangle(\tikzlastnode.north east);
      }
    }
  },
  decoration type/.style={
    decoration={coil,raise=4pt,amplitude=1pt,segment length=6pt}
  }
}

\begin{document}

\begin{tikzpicture}
\node[block,rotate=45,segment aspect=10,minimum height=50,font =\large,decorate this node={rotate=45}] (O) at(0,0) {Obstacle};
\end{tikzpicture}
\end{document}

The result:

enter image description here

Some remarks

The snakes library has been superseeded by decorations. Moreover, I switched the deprecated tikzstyle into tikzset as per Should \tikzset or \tikzstyle be used to define TikZ styles?.

Finally, for what concern the style decorate this node, be carefull to keep consistence with the transformations you apply to the node: see the option rotate=45 passed also to the style.

share|improve this answer
    
In my opinion, a postaction with raised decoration on the node path would make things slightly easier. –  percusse May 27 '13 at 7:50
    
I remember some problems of dimension too largeby applying a postaction directly to the node from trials with smartdiagram. That's why I preferred this approach. –  Claudio Fiandrino May 27 '13 at 8:33
    
I guess if you make this node smaller same problem would pop up but I agree it's not failproof. –  percusse May 27 '13 at 9:56
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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