Graphics, Figures & TablesHow can I name an arbitrary number of paths?

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
topsquark
Posts: 71
Joined: Wed Oct 05, 2022 10:30 pm

How can I name an arbitrary number of paths?

Post by topsquark »

Okay, this is likely a LyX problem, but I thought I'd see if there was another approach.

I'm trying to replicate a mosaic I found on one of the example pages. I haven't looked at the code (where's the fun in that?), and I won't until I have something approximating a result, but I am running into a problem:

I have to name 36 paths and find intersections between them. Now, the simplest way to do that is with a foreach loop: \foreach \s in {0,...,35} {
\path[name path=c\s] (120+\s*\angle:4) arc({-167.2+\s*\angle}:-219.2+\s*\angle:10) arc(39.2+\s*\angle:-12.8+\s*\angle:10) arc(60+\s*\angle:120+\s*\angle:4) -- cycle;
};

(I have to learn a simpler way to define that path!) Anway, I can find the intersection between c0 and c1:
\path[name intersections={of=c0 and c1,by=I0}];

and draw the needed circle through it:
\node [draw] at (O) [circle through={(I0)}] {};

This works... most of the time. For some reason I can't understand, the compiler starts not being able to find the curve c0 and I have to exit and reload the program (not just the file.) That's why I think this is a LyX issue.

However, it occurs to me that the way I have defined the curve names is, perhaps, not the best way to go about this.

Any thoughts?

-Dan

Here's the code for the first part of the mosaic:

Code: Select all

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections,through}
\newcommand*{\myangle}{10}
\begin{tikzpicture}[scale=0.6]
     \coordinate (O) at (0,0);
     \foreach \s in {0,...,35} {
          \path[name path=c\s] (120+\s*\myangle:4) arc({-167.2+\s*\myangle}:-219.2+\s*\myangle:10) arc(39.2+\s*\myangle:-12.8+\s*\myangle:10) arc(60+\s*\myangle:120+\s*\myangle:4) -- cycle;
          \draw (120+\s*\angle:4) arc({-167.2+\s*\myangle}:-219.2+\s*\myangle:10) arc(39.2+\s*\myangle:-12.8+\s*\myangle:10) arc(60+\s*\myangle:120+\s*\angle:4) -- cycle;
     };
     \draw (O) circle(12);
     \path[name intersections={of=c0 and c1,by=I0}];
     \node [draw] at (O) [circle through={(I0)}] {};
     \path[name intersections={of=c0 and c2,by=II0}];
     \node [draw] at (O) [circle through={(II0)}] {};
     \path[name intersections={of=c0 and c3,by=III0}];
     \node [draw] at (O) [circle through={(III0)}] {};
     \path[name intersections={of=c0 and c4,by=IV0}];
     \node [draw] at (O) [circle through={(IV0)}] {};
     \path[name intersections={of=c0 and c5,by=V0}];
     \node [draw] at (O) [circle through={(V0)}] {};
\end{tikzpicture}
Addendum: I'm sorry, I have no idea what
! Illegal parameter number in definition of \tikz@scan@point@coordinate.
<to be read again>
$
l.9 }
;
?
! Emergency stop.
is supposed to mean. I keep having trouble posting code here. Is there a tutorial I can read, or something?
Last edited by topsquark on Thu Aug 03, 2023 1:29 am, edited 1 time in total.

Recommended reading 2024:

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

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

kaiserkarl13
Posts: 707
Joined: Tue Mar 25, 2008 5:02 pm

How can I name an arbitrary number of paths?

Post by kaiserkarl13 »

I tinkered with this for a while, and there are a couple of issues. First, the command \angle causes problems; if I put \newcommand*{\myangle}{10} in there and replace all \angle with \myangle, it draws something. The trick is, the curves you are naming never intersect, which is why TikZ complains that there is no shape named "intersection-1" (because there is no intersection between c0 and c1).

If you run this example, you'll see what I mean:

Code: Select all

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections,through}
\newcommand*{\myangle}{20}
\begin{document}
\begin{tikzpicture}[scale=0.6]
     \coordinate (O) at (0,0);
     \foreach \s in {0,...,1} {
          \path[draw=green,name path=c\s] ({120+\s*\myangle}:4) 
            arc({-167.2+\s*\myangle}:{-219.2+\s*\myangle}:10);
            arc(39.2+\s*\myangle:-12.8+\s*\myangle:10)
            arc(60+\s*\myangle:120+\s*\myangle:4) -- cycle;
%          \draw[blue!\s!red] (120+\s*\myangle:4)
%            arc({-167.2+\s*\myangle}:-219.2+\s*\myangle:10)
%            arc(39.2+\s*\myangle:-12.8+\s*\myangle:10)
%            arc(60+\s*\myangle:120+\s*\myangle:4) -- cycle;
     };
     \draw (O) circle(12);
     % uncomment this next line to reveal the non-intersection error
     %\path[name intersections={of=c0 and c1,by=I0}];
%     \node [draw] at (O) [circle through={(I0)}] {};
%     \path[name intersections={of=c0 and c2,by=II0}];
%     \node [draw] at (O) [circle through={(II0)}] {};
%     \path[name intersections={of=c0 and c3,by=III0}];
%     \node [draw] at (O) [circle through={(III0)}] {};
%     \path[name intersections={of=c0 and c4,by=IV0}];
%     \node [draw] at (O) [circle through={(IV0)}] {};
%     \path[name intersections={of=c0 and c5,by=V0}];
%     \node [draw] at (O) [circle through={(V0)}] {};
\end{tikzpicture}
\end{document}
topsquark
Posts: 71
Joined: Wed Oct 05, 2022 10:30 pm

How can I name an arbitrary number of paths?

Post by topsquark »

Thank you for the \newcommand* statement. I haven't seen it written that way. I had never thought of \angle as a "command," just as a variable name. Am I wrong about that?

As to the code, \myangle=10, not 20 (though that isn't the issue.) The reason your curves don't intersect is that you are only drawing

(120+\s*\myangle:4) arc(-167.2+\s*\myangle:-219.2+\s*\myangle:10)

the first branch of the curve. (The path statement you posted has an extra ; in the middle!) I'll fix all that in my code in the OP and see what it does.

Thanks!

-Dan

Code: Select all

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections,through}
\newcommand*{\myangle}{10}
\begin{document}
\begin{tikzpicture}[scale=0.6]
     \coordinate (O) at (0,0);
     \foreach \s in {0,...,35} {
          \path[name path=c\s] (120+\s*\myangle:4) arc(-167.2+\s*\myangle:-219.2+\s*\myangle:10) arc(39.2+\s*\myangle:-12.8+\s*\myangle:10) arc(60+\s*\myangle:120+\s*\myangle:4) -- cycle;
          \draw (120+\s*\myangle:4) arc({-167.2+\s*\myangle}:-219.2+\s*\myangle:10) arc(39.2+\s*\myangle:-12.8+\s*\myangle:10) arc(60+\s*\myangle:120+\s*\myangle:4) -- cycle;
     };
     \draw (O) circle(12);
     \path[name intersections={of=c0 and c1,by=I0}];
     \node[draw,circle through={(I0)}] at (O) {};
\end{tikzpicture}
\end{document}
Post Reply