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.

Two questions:

  1. What is going wrong with these nodes that are defined from the intersections?
  2. Can this be automated with \foreach syntax to find the other vectors for the 2nd point? I couldn't figure that out.

\documentclass[tikz]{standalone}
\usepackage{amsmath}

\usetikzlibrary{intersections}
\usetikzlibrary{calc}

%  Used for both ellipses and circles                                               
\tikzset{%                                                                          
  partial ellipse/.style args = {#1:#2:#3}{%                                        
    insert path = {+ (#1:#3) arc (#1:#2:#3)}
  }
}

%  unit vectors                                                                     
\newcommand{\unit}[1]{\hat{\mathbf{#1}}}

\begin{document}
\begin{tikzpicture}
  \coordinate (O) at (0, 0);

  \draw[-latex] (O) -- (4, 0) node[pos = 1.1, font = \scriptsize] {\(x\)};
  \draw[-latex] (O) -- (0, 4) node[pos = 1.1, font = \scriptsize] {\(y\)};
  \draw[blue, name path = arc] (O) [partial ellipse = -15:75:3];


  \foreach \i/\angle in {1/60, 2/30}{
    \path[name path global = line\i] (O) -- (\angle:3.5);
    \path[name intersections = {of = arc and line\i, by = P\i}];
    \path[name path global = circ\i] (P\i) circle[radius = 1bp];

    \filldraw[black] (P\i) circle[radius = .025cm];
  }

  \node[coordinate, name intersections = {of = circ1 and arc}] (A1) at
  (intersection-1) {};
  \node[coordinate, name intersections = {of = circ1 and arc}] (A2) at
  (intersection-2) {};
  \draw[name intersections = {of = circ1 and arc}, -latex] (P1) --
  ($(A2)!.75cm!(A1)$) node[pos = 1.125, font = \tiny] {\(\unit{u}\)} coordinate
  (B1);

  \draw[-latex] (P1) -- ($(P1)!.75cm!-270:(B1)$) node[pos = 1.125,
  font = \tiny] {\(\unit{n}\)};
\end{tikzpicture}
\end{document}

From the image, we see that first point is drawing correctly it just has associated errors with it.

enter image description here

share|improve this question

1 Answer 1

up vote 4 down vote accepted

For the error you get now just use the following code inside your \foreach loop (pgf-manual p. 496):

\path[name path global/.expanded = line\i] (O) -- (\angle:3.5);
\path[name intersections/.expanded = {of = arc and line\i, by = P\i}];
\path[name path global/.expanded = circ\i] (P\i) circle[radius = 1bp];

This will permit you to use path defined inside the \foreach loop outside the loop.


If just copy your last command inside the \foreach loop you get the following error:

! Paragraph ended before \tikz@intersect@path@names@parse was complete.

This is because the of key (\tikz@intersect@path@names@parse) expects spaces around and which is obviously stripped if you use of = circ\i and arc, so you will need to use of = {circ\i} and arc.

\documentclass[tikz]{standalone}
\usepackage{amsmath}

\usetikzlibrary{intersections}
\usetikzlibrary{calc}

%  Used for both ellipses and circles                                               
\tikzset{%                                                                          
  partial ellipse/.style args = {#1:#2:#3}{%                                        
    insert path = {+ (#1:#3) arc (#1:#2:#3)}
  }
}

%  unit vectors                                                                     
\newcommand{\unit}[1]{\hat{\mathbf{#1}}}

\begin{document}
\begin{tikzpicture}
  \coordinate (O) at (0, 0);

  \draw[-latex] (O) -- (4, 0) node[pos = 1.1, font = \scriptsize] {\(x\)};
  \draw[-latex] (O) -- (0, 4) node[pos = 1.1, font = \scriptsize] {\(y\)};
  \draw[blue, name path = arc] (O) [partial ellipse = -15:75:3];


  \foreach \i/\angle in {1/60, 2/30 }{
    \path[name path global= line\i] (O) -- (\angle:3.5);
    \path[name intersections = {of = arc and line\i, by = P\i}];
    \path[name path global = circ\i] (P\i) circle[radius = 1bp];
    \filldraw[black] (P\i) circle[radius = .025cm];
    \node[coordinate, name intersections = {of = {circ\i} and arc}] (A1) at  (intersection-1) {};
    \node[coordinate, name intersections = {of = {circ\i} and arc}] (A2) at  (intersection-2) {};
    \draw[name intersections/.expanded = {of = {circ\i} and arc}, -latex] (P\i) -- ($(A2)!.75cm!(A1)$) node[pos = 1.125, font = \tiny] {\(\unit{u}\)} coordinate (B1);
  \draw[-latex] (P\i) -- ($(P\i)!.75cm!-270:(B1)$) node[pos = 1.125, font = \tiny] {\(\unit{n}\)};
  }


\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer

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.