## LaTeX forum ⇒ Graphics, Figures & Tables ⇒ intersection Topic is solved

Information and discussion about graphics, figures & tables in LaTeX documents.
kent
Posts: 42
Joined: Thu Oct 20, 2016 3:41 pm

### intersection

I have 4 intersections in this case, and want to draw and fill that number of circles. Question: Why does not my code do want I want it to do ?
See the attached .tex file.
Kent Holing
Attachments
intersections.tex

Stefan Kottwitz
Posts: 8705
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:
Hi Kent,

I don't have mypgfmacrolibrary.tex to test. Can you attach it, if it is relevant?

Without that, commenting it out, I get errors:

! Undefined control sequence.\UseTextAccent ...up \@firstofone \let \@curr@enc                                                   \cf@encoding \@use@text@en...l.21 }

Stefan

kent
Posts: 42
Joined: Thu Oct 20, 2016 3:41 pm
You do not need the library. I did run the input file without it.
It seems to be a problem with the \foreach loop.

Stefan Kottwitz
Posts: 8705
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:
Ok, since you did not mention the error but said that the code just doesn't do what you want it to do, I assumed the error is another thing that just with creating this example, and thought it's about doing something.

The total=\t variable is only locally defined in the current path, that's why the \t in your \foreach loop is a predefined LaTeX macro. This way you can make it globally available:

\draw [execute at begin node={\global\let\t=\t},       name intersections = {of = c1 and c2,total=\t}] ...

Stefn

Stefan Kottwitz
Posts: 8705
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:
Here is the modified code to get four filled circles at the intersection points:

\documentclass[margin=10pt]{standalone} \usepackage{tikz} %\input{mypgfmacrolibrary}\usetikzlibrary{intersections} \begin{document} \begin{tikzpicture} \coordinate (O) at (0,0); \coordinate (A) at (2.0,2.0); \draw [name path = c1, red, thick] (A) circle [radius = 4cm]; \draw [name path = c2, green, thin] (A) ellipse (5.0cm and 2.0cm); \draw [execute at begin node={\global\let\t=\t},       name intersections = {of = c1 and c2,total=\t}] (intersection-1) -- (intersection-2) -- (intersection-3) -- (intersection-4) -- cycle; \pgfmathsetmacro{\nr}{0}\foreach \point in {1,...,\t}  \filldraw[red] (intersection-\point) circle (0.5cm);\end{tikzpicture} \end{document}

intersection.png (12.36 KiB) Viewed 1196 times

Stefan

kent
Posts: 42
Joined: Thu Oct 20, 2016 3:41 pm
Thanks pointing this out.
This answers one part of my earlier posting on intersections on apparently differences between PGF 2.0 and PGF 3.0.
Kent

kent
Posts: 42
Joined: Thu Oct 20, 2016 3:41 pm
One additional question regarding the global value \t:
If we have a case with no intersections, it seems to me, based on testing, that \t is not defined.
It should really be defined to be 0 in such cases.
How can this be fixed?

Best regards,
Kent

Stefan Kottwitz
Posts: 8705
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:
Can you post your test case? I just don't have time now to construct another case. Also I expect \t to be 0 then, and we could work with \ifnum \t>0 ... \fi.

Stefan

kent
Posts: 42
Joined: Thu Oct 20, 2016 3:41 pm
See the attached .tex file where you find one example where the two paths intersect and the code works
and one example where the two paths do not intersect and the code does not work.
Kent
Attachments
latexforumposting.tex

kent
Posts: 42
Joined: Thu Oct 20, 2016 3:41 pm
I modified the example on page 982 in the PGF 3.0 manual to let the square be completely inside the ellipse
such that the number of intersection points should be 0. (See the attached file.)
As described in the manual, the origion is indeed highlighted.
In such case, I would prefer to not highlight any point. How can I achieve this? This posting is a direct follow-up
from the above.
Kent
Attachments
intersections4.tex