LaTeX forum ⇒ Graphics, Figures & Tablesintersection Topic is solved

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

intersection

Postby kent » Tue Dec 19, 2017 4:20 pm

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 7 times

User avatar
Stefan Kottwitz
Site Admin
Posts: 8596
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:

Postby Stefan Kottwitz » Tue Dec 19, 2017 5:44 pm

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:

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


Stefan
Site admin

kent
Posts: 39
Joined: Thu Oct 20, 2016 3:41 pm

Postby kent » Wed Dec 20, 2017 10:00 am

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: 8596
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:

Postby Stefan Kottwitz » Wed Dec 20, 2017 4:35 pm

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:

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


Stefn
Site admin

User avatar
Stefan Kottwitz
Site Admin
Posts: 8596
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:

Postby Stefan Kottwitz » Wed Dec 20, 2017 5:27 pm

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

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


intersection.png
intersection.png (12.36 KiB) Viewed 885 times


Stefan
Site admin

kent
Posts: 39
Joined: Thu Oct 20, 2016 3:41 pm

Postby kent » Thu Dec 21, 2017 9:19 am

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

Postby kent » Fri Jan 05, 2018 12:34 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

User avatar
Stefan Kottwitz
Site Admin
Posts: 8596
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:

Postby Stefan Kottwitz » Fri Jan 05, 2018 2:19 pm

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
Site admin

kent
Posts: 39
Joined: Thu Oct 20, 2016 3:41 pm

Postby kent » Fri Jan 05, 2018 2:55 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
(1.99 KiB) Downloaded 3 times

kent
Posts: 39
Joined: Thu Oct 20, 2016 3:41 pm

Postby kent » Mon Jan 08, 2018 9:59 am

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 3 times


Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: Google [Bot] and 6 guests