SmtC: Show me the Code
Ole Peter Smith
Instituto de Matemática e Estatística
Universidade Federal de Goiás
http://www.olesmith.com.br

TikZ (Palestra)
O conhecimento adquirimos com os livros e os mestres.
A sabedoria aprendemos com o povo e os humildes.
Cora Coralina
< Angles | Intersections | Programming >

Calculate Intersections

  • Draw: \draw [name path=l1] (-1,-1) -- ( 1,1);
    \draw [name path=l2] ( 1,-1) -- (-1,1);
  • Find Intersection:
    \path [name intersections={of=l1 and l2,by=X}];
  • Draw it:
    \filldraw (X) circle(1pt) node [right] {$X$};

TiKZ Listing: Fig.tikz.tex. PDF   PNG   SVG   ZIP*  
%TiKZ radians confuses \tkzMarkAngle and friends
\begin{tikzpicture}
  \tikzmath{\Size=5;};

  %Must be first...
  \filldraw[white](\Size,\Size) -- (-\Size,\Size) -- (-\Size,-\Size) -- (\Size,-\Size) -- cycle;

  \draw[-Latex] (-\Size,0) -- (\Size,0) node [right] {$x$};
  \draw[-Latex] (0,-\Size) -- (0,\Size,0) node [above] {$y$};
  
  \tikzmath{\a=2;};
  \tikzmath{\aa=-2;};
  \tikzmath{\b=0.5;};
  \tikzmath{\bb=0.5;};

  \tikzmath{\x=-4;};
  \tikzmath{\xx=4;};

  \filldraw [name path=l1]
  ($(\x,\a*\x+\b)$)
  circle(2pt)
  node [below] {$y=\a\cdot x+\b$}
  --
  ($(\xx,\a*\xx+\b)$)
  circle(1pt);
  
  \filldraw [name path=l2]
   ($(\x,\aa*\x+\bb)$) 
  circle(3pt)
  node [above] {$y=\aa\cdot x+\bb$}
  --
  ($(\xx,\aa*\xx+\bb)$)
  circle(1pt);

  \path [name intersections={of=l1 and l2,by=X}];
  \filldraw (X) circle(1pt) node [right] {$X$};

  \draw [name path=c1] (0,0) circle(4);
  \draw [name path=c2] (0,0) circle(2);

  
  \path [name intersections={of=l1 and c1,by=X1}];
  \filldraw (X1) circle(1pt) node [above] {$X$};

  %Several intersection points
  \draw [name intersections={of=l1 and c2, total=\n}]  
     \foreach \i in {1,...,\n}{
        (intersection-\i)
       circle(2pt)
       node [anchor=south west]   {$~X_\i$}
     };
        
\end{tikzpicture}
< Angles | Intersections | Programming >
Messages:
0 secs.