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 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

share|improve this question
    
Have you tried drawing the paths using color=white in order to determine the intersections? –  John Kormylo Feb 27 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 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 at 17:55
1  
1  
See also this question, whose answers may be helpful. –  Charles Staats Feb 28 at 11:38

1 Answer 1

up vote 4 down vote accepted

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

share|improve this answer
    
I don't understant how I can achieve with this help ? –  Tarass Feb 27 at 15:55
    
Okay, I replaced the it with a full solution. –  John Kormylo Feb 27 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 at 6:05
1  
The problem is that TeX doesn't really support arrays, which makes it difficult to store numbers. –  John Kormylo Feb 28 at 17:15

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.