7

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}

enter image description here

9
  • Have you tried drawing the paths using color=white in order to determine the intersections? 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. 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
  • 1
  • 1
    See also this question, whose answers may be helpful. Feb 28 '14 at 11:38
6

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
\draw[color=blue, name path=EllA] (0,0) circle[x radius=1, y radius=2];

%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}%
    {(i-\s) circle[radius=1pt] node{\footnotesize\s}};

\end{tikzpicture}
\end{document}

ellipses

4
  • I don't understant how I can achieve with this help ?
    – Tarass
    Feb 27 '14 at 15:55
  • Okay, I replaced the it with a full solution. Feb 27 '14 at 21:05
  • Thank you very much. But as I said, I have an ellipse calculated by a complex process, in wich I don't know the small nor the big radius. As tikz made the calculations for the path for me I expect than tikz can cut the path on point it has calculated itself then draw the line following this very path between such points. If tikz is not made for this (not yet ;-) ), let just a specialist says it : Tarass you ask for impossible thinks ! ;-)
    – Tarass
    Feb 28 '14 at 6:05
  • 1
    The problem is that TeX doesn't really support arrays, which makes it difficult to store numbers. Feb 28 '14 at 17:15
0

I'm not completely clear what you are after, but I've recently developed the ability to work with subpaths in the spath3 package.

\documentclass[a4paper]{article}
%\url{https://tex.stackexchange.com/q/162687/86}
\usepackage[marginparsep=3pt, top=2cm, bottom=1.5cm, left=3cm, right=1.5cm]{geometry}

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

\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[spath/save=EllA]
    (EA0)
    \foreach \A in {10,20,...,350} {%
        --(EA\A) } --cycle ;

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

\tikzset{
  spath/split at intersections with={EllA}{EllB},
  spath/get components of={EllA}\cpts
}

\draw[
  blue,
  spath/use=\getComponentOf\cpts{1},
  spath/use={\getComponentOf\cpts{2},weld},
  spath/close=current
];

\draw[
  blue,
  dashed,
  spath/use=\getComponentOf\cpts{3},
  spath/use={\getComponentOf\cpts{4},weld},
];

\draw[spath/use=EllB];

\end{tikzpicture}
\end{document}

Subpaths of an ellipse

2
  • Hello Andrew. It was a long time ago. I was trying to copy your emptying cylinder. I had much free time but no more now for this. Thank you very much for your concern.
    – Tarass
    Mar 11 at 7:30
  • @Tarass Interesting! I do realise this was asked a while back, I was adding my answer more for posterity than specifically for you as questions like this can form a repository of techniques and so I wanted to add this one to it as it is relatively new. Mar 12 at 20:26

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.