Graphics, Figures & Tablesintersection

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

intersection

Post by kent »

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
(758 Bytes) Downloaded 532 times

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Stefan Kottwitz
Site Admin
Posts: 10328
Joined: Mon Mar 10, 2008 9:44 pm

intersection

Post by Stefan Kottwitz »

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:

Code: Select all

! Undefined control sequence.
\UseTextAccent ...up \@firstofone \let \@curr@enc 
                                                  \cf@encoding \@use@text@en...
l.21 }
Stefan
LaTeX.org admin
kent
Posts: 57
Joined: Thu Oct 20, 2016 3:41 pm

intersection

Post by kent »

You do not need the library. I did run the input file without it.
It seems to be a problem with the \foreach loop.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10328
Joined: Mon Mar 10, 2008 9:44 pm

intersection

Post by Stefan Kottwitz »

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:

Code: Select all

\draw [execute at begin node={\global\let\t=\t},
       name intersections = {of = c1 and c2,total=\t}] ...
Stefn
LaTeX.org admin
User avatar
Stefan Kottwitz
Site Admin
Posts: 10328
Joined: Mon Mar 10, 2008 9:44 pm

intersection

Post by Stefan Kottwitz »

Here is the modified code to get four filled circles at the intersection points:

Code: Select all

\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
intersection.png (12.36 KiB) Viewed 7301 times
Stefan
LaTeX.org admin
kent
Posts: 57
Joined: Thu Oct 20, 2016 3:41 pm

intersection

Post by kent »

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: 57
Joined: Thu Oct 20, 2016 3:41 pm

intersection

Post by kent »

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
User avatar
Stefan Kottwitz
Site Admin
Posts: 10328
Joined: Mon Mar 10, 2008 9:44 pm

intersection

Post by Stefan Kottwitz »

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
LaTeX.org admin
kent
Posts: 57
Joined: Thu Oct 20, 2016 3:41 pm

intersection

Post by kent »

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
(1.99 KiB) Downloaded 501 times
kent
Posts: 57
Joined: Thu Oct 20, 2016 3:41 pm

intersection

Post by kent »

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
(726 Bytes) Downloaded 468 times
Post Reply