4

I have two pathes the firt is to be fully drawed, but only a part of the second using intersection point with the first.

Here an example: I want to draw only the upper part of the square (dashed) as close cycle to intersection points 1 and 3. But I have no idea how to do that. I usually use metapost and it will be a piece of cake to do that. I hope it is the same with pgf-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},}

\begin{document}
\begin{tikzpicture}

% drawed just for explanation
\draw[thin,dashed] (-1,-1)--(1,-1)--(1,1)--(-1,1)--cycle ;

\path[name path=carre] (-1,-1)--(1,-1)--(1,1)--(-1,1)--cycle ;
\draw[name path=paral,blue] (-1.5,-.5)--(.5,-.5)--(1.5,.5)--(-.5,.5)--cycle ;

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

\end{tikzpicture}
\end{document}

enter image description here

Tarass
  • 16,912
  • Do you want to name those instersections? In other words, do you want those red circles in your final diagram? –  Feb 27 '14 at 00:57
  • Have a nice day. I'll start a new question more explicit. Thank's. – Tarass Feb 27 '14 at 09:33

1 Answers1

6

Like this?

enter image description here

I used \clip inside a scope

\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},}

\begin{document}
\begin{tikzpicture}

% drawed just for explanation
%\draw[thin,dashed] (-1,-1)--(1,-1)--(1,1)--(-1,1)--cycle ;

\begin{scope}
\clip (-1,1)  rectangle (1,0);
\draw[dashed,thin,fill=olive!40,name path global=carre] (-1,-1)--(1,-1)--(1,1)--(-1,1)--cycle ;
\end{scope}
\draw[name path=paral,blue] (-1.5,-.5)--(.5,-.5)--(1.5,.5)--(-.5,.5)--cycle ;

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

\end{tikzpicture}
\end{document}

Without \clip

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

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

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

\begin{document}
\begin{tikzpicture}

\draw[name path=paral,blue] (-1.5,-.5)--(.5,-.5)--node[coordinate,midway](a){}(1.5,.5)--(-.5,.5)-- node[coordinate,midway](b){}cycle ;

\begin{scope}[on background layer]
\draw[dashed,thin,fill=olive!40,name path global=carre] (b)-- ++(0,1)-- ++(2,0)--(a)-- cycle ;
\end{scope}


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

\end{tikzpicture}
\end{document}

enter image description here

At some other point

Using pos=<value> instead of midway like

\draw[name path=paral,blue] (-1.5,-.5)--(.5,-.5)--node[coordinate,pos=0.8](a){}(1.5,.5)--(-.5,.5)-- node[coordinate,pos=0.2](b){}cycle ;

you get

enter image description here

I have used the relative coordinates ++(x,y) syntax here. Please note that ++ changes the relative origin to the current point unlike single +.

Now some arbitrary plane:

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

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

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

\begin{document}
\begin{tikzpicture}

\draw[name path=paral,blue] (-1.5,-.5)--node[coordinate,pos=0.8](a){}(.5,-.5)--(1.5,.5)--(-.5,.5)-- node[coordinate,pos=0.2](b){}cycle ;

\begin{scope}[on background layer]
\coordinate[above= 1cm of a] (c);
\coordinate[above= 1cm of b] (d);
\draw[dashed,thin,fill=olive!40,name path global=carre] (b)-- (d)-- (c)--(a)-- cycle ;
\end{scope}


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

\end{tikzpicture}
\end{document}

enter image description here

PS: I didn't work on the intersection points thinking that it is not relevant for the question.

  • Feel free to ask for clarifications. I think I didn't understand the requirement fully/properly. –  Feb 27 '14 at 01:25
  • Thank's. But I put a simple example and \clip (-1,1) rectangle (1,0); is 'from the hat'. Some times you can't anticipate nor calculate in witch path you can enclose the things to clip. I'd like a solution following the path to have a new cliped path. I read pgfmanual (not all ;-)) but with attention, and I did not found a wait to make several operation on a path in different command: pre- post-action use the same command. If I want to draw a path and the same rotated or shifted but dashed I don't know how. As I said, in metapost it is basic. – Tarass Feb 27 '14 at 06:43
  • I saw in pgfmanual, low level pgf command like pgfpathmoveto and so on, but it uses pgfpoint syntax and not node syntax. I a little confused with this. – Tarass Feb 27 '14 at 06:47
  • I drawed a 'simple' examle, that you can easy enclose in a sqare. In the case that the path is more complicated and I don't want to calculate how to enclose it in something, how should I do. Second, if I want to make one cycle with the upper part of the sqare and the front part of the blue line ? – Tarass Feb 27 '14 at 06:59
  • More than that, how did you know that the intesection line is (S-1)--(S-3) befor drawing the second path ? I'd like a solution where pgf-tikz makes the calculations for me. – Tarass Feb 27 '14 at 07:10
  • Thanks for your answer, I learn from it. But how do you know in advance where to put a,b,c,d nodes ? Again in a case of a complicated path depending of several parameters, how to ask pgf-tikz to do the calculations. More than that, the two pathes can have 0 or 4 intersection points, I plan to ditinguish (if possible) knowing their number (pgf-tikz give this number) the clippind or cutting process. Finaly I want just change parameters in the bigining of the image and let tiks make the computation. Is it possible with tikz or not ? – Tarass Feb 27 '14 at 07:33
  • @Tarass I think I still don't understand. Are you drawing both the rectangles? Then find out their intersections? And then fill out the the uppaer half? Is that the work flow? I thought you draw the blue one. And then draw the upper plane at some points. –  Feb 27 '14 at 07:41
  • Let replace the rectangles by ellipses for example. – Tarass Feb 27 '14 at 07:45
  • Hello Harish, thank you. My problem is that I have a path (let say an ellipse with 12 calculated points). When I define this points by a path command, how then to draw one part on it ? I can not calculate them and draw them at the same time, because I need the full path to calculate the intersection point with another path. Is that more clear ? The intersection with 2 tikz ellispses is easy, the difficult point is a point by point caluclates cycle. Is it more clear ? In fact the question remuses in how to freely manipulate pathes knowin them by name without drawing them ? (as in metapost ;-)) – Tarass Feb 27 '14 at 08:20
  • @Tarass I got it (I think) but why don't you give your actual path so that it is easy for us :) (I am still at my lunch). –  Feb 27 '14 at 08:22
  • Followes here : http://tex.stackexchange.com/questions/162687/extract-a-part-of-a-path-and-reuse-it-as-part-of-a-new-one – Tarass Feb 27 '14 at 11:59