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

  • Do you want to name those instersections? In other words, do you want those red circles in your final diagram? – user11232 Feb 27 '14 at 0:57
  • Have a nice day. I'll start a new question more explicit. Thank's. – Tarass Feb 27 '14 at 9:33
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.

| improve this answer | |
  • Feel free to ask for clarifications. I think I didn't understand the requirement fully/properly. – user11232 Feb 27 '14 at 1: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 6: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 6: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 6: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 7:10

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.