[Solved] Line intersection with unit circle using TikZ/PGF
Update:
I was able to track it down myself. I was missing the Everyshi package, included in the ms package (CTAN: directory: /tex-archive/macros/latex/contrib/ms). Now I can use the CVS version and not get "GUI framework cannot be initialized".
The working code looks like this:
Code:
\begin{tikzpicture}
[scale=1.5,line cap=round,
% Styles
axes/.style={thick},
information text/.style={rounded corners,inner sep=1ex}]
\usetikzlibrary{arrows,calc,intersections}
% The graphic
\draw[help lines,step=0.5cm] (-1.4,-1.4) grid (1.4,1.4);
\draw[name path=unitcircle] (0,0) circle(1cm);
\begin{scope}[axes]
\draw[->] (-1.5,0) -- (1.5,0) node[right] {$x$} coordinate(x axis);
\draw[->] (0,-1.5) -- (0,1.5) node[above] {$y$} coordinate(y axis);
\foreach \x/\xtext in {-1, -.5/-\frac{1}{2}, .5/\frac{1}{2}, 1}
\draw[xshift=\x cm] (0pt,1pt) -- (0pt,-1pt) node[below,fill=white,inner sep=0.2ex] {\tiny $\xtext$};
\foreach \y/\ytext in {-1, -.5/-\frac{1}{2}, .5/\frac{1}{2}, 1}
\draw[yshift=\y cm] (1pt,0pt) -- (-1pt,0pt) node[left,fill=white,inner sep=0.2ex] {\tiny $\ytext$};
\end{scope}
\foreach \t/\ttext in {-1,-0.5,...,1}
{
\path[name path=myline] (1,0) -- (0,\t) node[sloped, near end, above=-2pt] {\tiny \color{blue}$\scriptscriptstyle -t = \ttext$} -- (-1,2*\t);
\path [name intersections={of=unitcircle and myline, by={C, C'}}];
\draw [name path=C--C',red] (C) -- (C');
\fill [red, name intersections={of=unitcircle and myline}]
(intersection-1) circle (0.3mm)
(intersection-2) circle (0.3mm);
}
\draw[yshift=-1.7cm] node[below,text width=2cm,information text] {Figure 1.1};
\end{tikzpicture}
I have been trying to fix this for many hours now and I cannot find any working solution. So if anyone can help, please do so.
What I want to do is to find the intersection point (and add a dot/circle) between the line generated with this (see full TikZ code below):
Code:
\foreach \t/\ttext in {-1,-0.5,...,1}
{
\draw (1,0) -- (0,\t) node[sloped, near end, above] {\tiny $-t = \ttext$} -- (-1, 2*\t);
}
and a unit circle generated with
Code:
\draw (0,0) circle (1cm);
or
Code:
\node (c1) at (0,0) [draw,circle,scale=9] {};
I have tried several approaches but nothing seems to work. Tries include this "solution":
Nabble - pgf-users - Intersection Line/Circle
Nabble - pgf-users - Intersection Line/Circle (2)
but it just generates errors of "Undefined control sequence. <recently read> \pgfsetpath" and various tries have easily reached 100+ errors.
I'm using the latest CVS build of TikZ/PGF but slightly mixed with the 2.00 final build. The mixing is because I got "GUI framework cannot be initialized" at the file "pgfutil-latex.def" with just pure CVS. Perhaps it is causing problem, but if so, help to install it correctly is appreichiated.
I also use TeXnicCenter 1.0 rc, as the working enviroment together with MiKTeX 2.8 basic. And I have tried to set install packages on the fly to Yes, but with no success.
By the way: I know the intersection points are given by:
 = (\frac{t^2-1}{t^2+1},\frac{2t}{t^2+1})<br />
)
but it seems like I cannot use these expressions as coordinates (using \t instead of t) because it seems like the dividing is causing trouble.
Full code (except \usepackage{tikz} and some document things):
Code:
\begin{tikzpicture}
[scale=1.5,line cap=round,
% Styles
axes/.style={thick},
information text/.style={rounded corners,inner sep=1ex}]
\usetikzlibrary{arrows,calc,intersections}
% Colors
\colorlet{anglecolor}{green!50!black}
% The graphic
\draw[help lines,step=0.5cm] (-1.4,-1.4) grid (1.4,1.4);
%\draw (0,0) circle (1cm);
\node (c1) at (0,0) [draw,circle,scale=9] {};
\begin{scope}[axes]
\draw[->] (-1.5,0) -- (1.5,0) node[right] {$x$} coordinate(x axis);
\draw[->] (0,-1.5) -- (0,1.5) node[above] {$y$} coordinate(y axis);
\foreach \x/\xtext in {-1, -.5/-\frac{1}{2}, .5/\frac{1}{2}, 1}
\draw[xshift=\x cm] (0pt,1pt) -- (0pt,-1pt) node[below,fill=white] {\tiny $\xtext$};
\foreach \y/\ytext in {-1, -.5/-\frac{1}{2}, .5/\frac{1}{2}, 1}
\draw[yshift=\y cm] (1pt,0pt) -- (-1pt,0pt) node[left,fill=white] {\tiny $\ytext$};
\end{scope}
\foreach \t/\ttext in {-1,-0.5,...,1}
{
\draw (1,0) -- (0,\t) node[sloped, near end, above] {\tiny $-t = \ttext$} -- (-1, 2*\t);
%\draw[red] (intersection cs:
first line={(1,0)--(0,\t)},
second line={(-1,-2)--(-1,2)})
circle (5pt);
%\draw[red] (intersection of (1,0)--(0,\t) and (-1,-2)--(-1,2)) circle (5pt);
}
\end{tikzpicture}