# Tikz - change object border line type - combining solid and dashed line

I would like to help with improving next Feynman picture. A few guys helped me with location ellipse in the irregular shaped object (question 74335).

The TikZ code is:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections, calc}

\begin{document}
\begin{figure}[hb!]
\centering
\begin{tikzpicture}
\coordinate (dS) at (1.5,0.5);
plot [smooth cycle] coordinates
{ (0,0) (1,-1) (3,0) (2.5,2) (3,3) (3,4) (2,5) (-1,3) };
\draw (3,4) node[right]{$S_a$};
\draw (0,0) node[below]{$S_b$};
% ploska dS
node[below, text=black]{$dS$} rectangle +(0.5,0.5);
\draw [->] (dS) ++ (0.25,0.25) -- +(30:0.5) node[right]{$\vec{n}$};
\draw [->] (dS) ++ (0.25,0.25) -- +(60:0.7) node[right]{$\vec{C}$};
% text
\draw [fill=black] (2,4) circle (0.05) node[above, black]{$V_1$};
\draw [fill=black] (1,0.5) circle (0.05) node[above, black]{$V_2$};
% line - division of object
\path [name path=line1](-1.5,3) -- (3,2);
% Intersections
\path [name intersections={of=teleso and line1, name=cross}];
% ellipse
\coordinate (A) at (cross-1);
\coordinate (B) at (cross-2);
\fill [color=cyan, opacity=0.25] let \p1=(A),\p2=(B),
\n1={atan2(\y2-\y1,\x2-\x1)},\n2={veclen(\y2-\y1,\x2-\x1)} in
[rotate=90-\n1] ($(A)!0.5!(B)$) ellipse (\n2/2 and 0.7cm);
% vectors
\draw [->] let \p1=(A),\p2=(B),
\n1= {atan2(\y2-\y1,\x2-\x1)} in
($(A)!0.5!(B)$) -- +(360-\n1:1)  node[right]{$\vec{n}_1$};  % relative
\draw [->, dashed] let \p1=(A),\p2=(B),
\n1= {atan2(\y2-\y1,\x2-\x1)} in
($(A)!0.5!(B)$) -- +(180-\n1:1) node[right]{$\vec{n}_2$};   % relative
\end{tikzpicture}
\end{figure}
\end{document}


## Questions

1. In line with command \shade[bottom color=gray!10!brown,opacity=0.50, shading angle=60](dS) node[below, text=black]{$dS$} rectangle +(0.5,0.5); node has defined text colour with text = black, but as you can see, the text "dS" in the picture is not black.
2. Furthermore, I would like to imply three-dimensional character of the object using boundary lines of the ellipse. One part must be drawn with a solid line, and the second part (rear body) shall be dashed. Ellipse is drawn by the the \fill command.
3. How can I better specify the text position (The text "Sa" is too stuck on an object)

## Output

-

For the text dS I suggest the workaround using an extra node:

\shade[
bottom color=gray!10!brown,
opacity=0.50,
] (dS) rectangle +(0.5,0.5);
\node [below] at (dS) {$dS$};


You probably want to make that more user-friendly (single macro, no repeated calculations) …

\draw[very thick,cyan] let \p1=(A),
\p2=(B),
\n1={atan2(\y2-\y1,\x2-\x1)},
\n2={veclen(\y2-\y1,\x2-\x1)}
in [rotate=90-\n1] ($(A)!0.5!(B)+(0:\n2/2)$) arc[start angle=0,
delta angle=180,

\draw[very thick,dashed,cyan] let \p1=(A),
\p2=(B),
\n1={atan2(\y2-\y1,\x2-\x1)},
\n2={veclen(\y2-\y1,\x2-\x1)}
in [rotate=90-\n1] ($(A)!0.5!(B)+(180:\n2/2)$) arc[start angle=180,
delta angle=180,


gives

The positioning can be fine tuned via values to the right, below, left, etc. keys:

\draw (3,4) node[right=1mm] {$S_a$};
\draw (0,0) node [left=1mm] {$S_b$};

-
Thank you very much... Please, would you have any idea, how to draw an ellipse, so that part was drawn with a solid line and the second dashed line. –  jafan Sep 29 '12 at 17:32
@jafan I've updated my answer. Is that something you had in mind? –  Qrrbrbirlbel Sep 29 '12 at 17:53
Thank you for your answer, I am satisfied. :-) –  jafan Sep 29 '12 at 19:55
@jafan I think I just have understood what you wanted. You may want to rearrange your commands, so that the not-dashed part will be drawn over the n2 vector. Furthermore, I'd add something like \fill [cyan!50!black,opacity=0.7] let \p1=(A),\p2=(B), \n1= {atan2(\y2-\y1,\x2-\x1)}, \n2={veclen(\y2-\y1,\x2-\x1)} in [rotate=90-\n1] ($(A)!0.5!(B)$) ellipse ({\n2/2*.05} and 0.7cm*.05);. (behind n1, in front of n2: screenshot). –  Qrrbrbirlbel Sep 29 '12 at 20:36
It is very interesting what can be combined in a single drawing command.Thanks. –  jafan Sep 29 '12 at 23:22