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.

This question led to a new package:
pst-intersect

In my experience, there is no macro in PSTricks to get the intersection nodes of two curves. Is it possible to do this in PSTricks? Or Am I am dreaming an impossible thing?

\documentclass[pstricks,border=12pt]{standalone}

\begin{document}
\begin{pspicture}[showgrid](4,3)
    \pscurve[linecolor=red](0,3)(1,1)(2,3)(3,2)(4,0)
    \pscurve[linecolor=blue](0,0)(1,3)(2,1)(3,1)(4,3)
\end{pspicture}
\end{document}

enter image description here

share|improve this question
    
Anything that can be done by TikZ can also be done by PSTricks. However, the reverse is not necessarily correct. –  cyanide-based food Jun 26 '13 at 19:37
3  
Seems appropriate that you get a tikz solution to your PSTricks question given your history :) –  cmhughes Jun 26 '13 at 21:08
    
convert both \pscurve to pathforall and then compare both values. PSTricks has some other examples for pathforall, so you can see how it works. –  Herbert Sep 10 '13 at 11:17
    
@CodeMocker Your first statement is incorrect. –  Paul Gaborit Feb 7 at 0:43
    
@PaulGaborit: Why? –  cyanide-based food Feb 7 at 0:52

2 Answers 2

up vote 6 down vote accepted

I just released a new PSTricks package pst-intersect, which can calculate the intersections of almost arbitrary paths.

Concerning your curves, you can calculate the intersections as follows:

\documentclass{article}
\usepackage{multido, pst-intersect}
\thispagestyle{empty}
\begin{document}
\begin{pspicture}[showgrid](4,3)
  \pssavepath[linecolor=red]{A}{\pscurve(0,3)(1,1)(2,3)(3,2)(4,0)}
  \pssavepath[linecolor=blue]{B}{\pscurve(0,0)(1,3)(2,1)(3,1)(4,3)}
  \psintersect[showpoints, name=C]{A}{B}
  \pstracecurve[linewidth=2\pslinewidth, istart=2, istop=3]{C}{A}
  \multido{\i=1+1}{3}{\uput[0](C\i){\i}}
\end{pspicture}
\end{document}

With the result

enter image description here

This also shows some other package features: Using the intersection nodes, and retracing parts of saved paths.

In order to get the coordinates of the intersection nodes, you can either use pst-nodes's parameter saveNodeCoors, or the package macro \psGetIsectCenter (both options available since version 0.3). The values can then be shown with \psPrintValue of the pst-tools package:

\documentclass{article}
\usepackage{multido, pst-intersect, pst-tools}
\thispagestyle{empty}
\begin{document}
\begin{pspicture}[showgrid](4,3)
  \pssavepath[linecolor=red]{A}{\pscurve(0,3)(1,1)(2,3)(3,2)(4,0)}
  \pssavepath[linecolor=blue]{B}{\pscurve(0,0)(1,3)(2,1)(3,1)(4,3)}
  \psintersect[showpoints, name=C, saveNodeCoors]{A}{B}
  \pstracecurve[linewidth=2\pslinewidth, istart=2, istop=3]{C}{A}
  \multido{\i=1+1}{3}{\uput[0](C\i){\i}}
\end{pspicture}

\bigskip

\makebox[4em]{X} \makebox[4em]{Y}\\
\multido{\i=1+1}{3}{%
  \makebox[4em]{\psPrintValue{N-C\i.x}}
  \makebox[4em]{\psPrintValue{N-C\i.y}}\\
}%

\makebox[4em]{X} \makebox[4em]{Y}\\
\multido{\i=1+1}{3}{%
  \makebox[4em]{\psPrintValue{\psGetIsectCenter{C}{}{\i} I-C\i.x}}
  \makebox[4em]{\psPrintValue{\psGetIsectCenter{C}{}{\i} I-C\i.y}}\\
}%
\end{document}

enter image description here

share|improve this answer
    
Can we refer to each intersection point by name for later use such as putting a label at that point? –  cyanide-based food Feb 7 at 0:54
    
I updated the answer to show some features and the new syntax for the newly released package (will appear soon on CTAN). –  Christoph Feb 18 at 23:28
    
Very nice additional features. Thanks. –  cyanide-based food Feb 18 at 23:57
    
Is it possible to get the coordinates of the intersection points? –  Svend Tveskæg Feb 21 at 12:35
    
@SvendTveskæg All the coordinates are stored on the Postscript level in an array Points inside the dictionary PIT@<name> that belongs to the intersection. For the above example, you can see it e.g. by putting \makeatletter\PIT@Verb{ PIT@C /Points get == }\makeatother somewhere after the \psintersect call. –  Christoph Feb 21 at 15:37

Here's how this could be done with TikZ using the intersections library:

enter image description here

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{intersections}

\begin{document}
\begin{tikzpicture}
    \draw [red, smooth, name path=first] plot coordinates {(0,3)(1,1)(2,3)(3,2)(4,0)};
    \draw [blue, smooth, name path=second] plot coordinates {(0,0)(1,3)(2,1)(3,1)(4,3)};
    \draw [thick, name intersections={of=first and second, total=\n}]
        \foreach \i in {1,...,\n}{
            (intersection-\i) circle [radius=3pt]
        };
\end{tikzpicture}
\end{document}
share|improve this answer
3  
+1: Thank you very much for answering. Unfortunately no bounty for TikZ solution. :-) –  cyanide-based food Jun 26 '13 at 19:29
1  
show it with the same coordinates as in the above example ... ;-) –  Herbert Jul 6 '13 at 10:31
2  
@Herbert: "Please"... ;-) –  Jake Jul 6 '13 at 11:57
1  
Your comment does not get enough attention in this link. –  cyanide-based food Jul 6 '13 at 12:03
1  
@Yake: but your curves look fare different. You know, that you have no equivalent function in tikZ for \pscurce... ;-) –  Herbert Jul 6 '13 at 12:50

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.