# Extract a part of a path and reuse it as part of a new one

I want to draw the blue line part 1-2-3-1 filled and the blue line part 1-4-3 dashed. The definition of the blue line (EllA path) is made of computed nodes.

I can't find intersection points during preaction of the drawing because tikz doesn't know the name of the path at this time. It will be nice if it will become possible in a next version of tikz.

I need to extract a part of EllA path (and I don't know if it's possible, steel asking the question ?) and draw it after, but to determine the intersection points it has to be drawed (at least without the draw option), but how to draw again a part of it even reuse it as part of a new path ?.

It is a vicious ellipse ;-)

PS clip half of the blue line is not a solution has I don't know his shape in advance. I want a dynamic solution based only on pathes themselves. If such a solution is possible with tikz.

\documentclass[a4paper]{article}
\usepackage[marginparsep=3pt, top=2cm, bottom=1.5cm, left=3cm, right=1.5cm]{geometry}

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

\tikzset{small dot/.style={fill=black,circle,scale=0.3},}

\newcommand{\EllA}[1]{%
\pgfmathsetmacro\CX{1*cos(#1)}
\pgfmathsetmacro\CY{2*sin(#1)}
}

\begin{document}
\begin{tikzpicture}

% Complex computed path
% here an ellipse for the example
\foreach \A in {0,10,...,350} {%
\EllA{\A} ;
\coordinate (EA\A) at (\CX,\CY) ;
}

% The draw option is here to see what it looks like
% but I just want to draw a part of it
\path[name path=EllA,draw,blue]
(EA0)
\foreach \A in {10,20,...,350} {%
--(EA\A) } --cycle ;

% Another path who may be computed as the first
\path[name path=EllB,draw,xslant=tan(30)] (0,0) circle (1) ;

\fill [red,
name intersections={of=EllA and EllB,
name=i,sort by=EllA,
total=\t}]
[every node/.style={above left, black, opacity=1}]
\foreach \s in {1,...,\t}
{(i-\s) circle (1pt) node {\footnotesize\s}};

\path[draw] (i-2)--(i-4) ;

\end{tikzpicture}
\end{document}


-
Have you tried drawing the paths using color=white in order to determine the intersections? –  John Kormylo Feb 27 '14 at 15:32
Come to think of it, you could draw the dashes in white after you draw them in solid color. –  John Kormylo Feb 27 '14 at 15:34
How to do this on half a path. It is the question : how to extract a part of the path... –  Tarass Feb 27 '14 at 17:55
–  John Kormylo Feb 27 '14 at 19:19

I'm not sure if these are the arcs you wanted filled. I assumed that there was a reason for drawing a line from (i-2) to (i-4).

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{calc,fpu,intersections}

\tikzset{small dot/.style={fill=black,circle,scale=0.3},}

\newlength{\cx}
\newlength{\cy}

\newcommand{\myangle}[2]{% #1 = coordinate name, #2 = macro name
\pgfextractx{\cx}{\pgfpointanchor{#1}{center}}%
\pgfextracty{\cy}{\pgfpointanchor{#1}{center}}%
\pgfmathparse{atan2(\cx,0.5\cy)}%
\let#2=\pgfmathresult}

\newcommand{\myotherangle}[2]{% #1 = coordinate name, #2 = macro name
\pgfextractx{\cx}{\pgfpointanchor{#1}{center}}%
\pgfextracty{\cy}{\pgfpointanchor{#1}{center}}%
\pgfmathparse{atan2(\cx-tan(30)*\cy,\cy)}%
\let#2=\pgfmathresult}

\begin{document}
\begin{tikzpicture}

%first ellipse

%second ellipse
\draw[name path=EllB,xslant=tan(30)] (0,0) circle(1);

%intersections
\path[name intersections={of=EllA and EllB,
name=i,sort by=EllA,total=\t}];

\draw (i-2)--(i-4);

%dashed line from i-1 to i-2
\myangle{i-1}{\angleA}%
\myangle{i-2}{\angleB}%
\draw[color=white,dashed] (i-1) arc(\angleA:\angleB:1 and 2);

%dashed line from i-2 to i-3
\myotherangle{i-2}{\angleC}%
\myotherangle{i-3}{\angleD}%
\draw[color=white,dashed,xslant=tan(30)] (i-2) arc(\angleC:\angleD:1);

%fill arc from i-2 to i-4
\myangle{i-2}{\angleA}%
\myangle{i-4}{\angleB}%
\fill[color=blue,opacity=.2] (i-2) arc(\angleA:\angleB+360:1 and 2);

%fill arc from i-1 to i-4
\myangle{i-1}{\angleA}%
\fill[color=blue,opacity=.2] (i-4) arc(\angleB:\angleA:1 and 2);

%unfill arc from i-1 to i-4
\myotherangle{i-4}{\angleC}%
\myotherangle{i-1}{\angleD}%
\path[draw=black,fill=white,xslant=tan(30)] (i-4) arc(\angleC:\angleD:1);

% draw intersections
\fill[color=red, every node/.style={above left, black, opacity=1}]
\foreach \s in {1,2,3,4}%