TransWikia.com

TikZ intersection command with strange behavior

TeX - LaTeX Asked by B. Dors on December 14, 2020

I am trying to put some nodes at the intersection of a circle with some bissectors. However, the intersections are not behaving how I supposed they should.

The text wrong should be placed at the intersection of circle and gray line, but it is somehow at an apparently random place:

Current situation

Furthermore, if the commented lines are uncommented, both intersections are put at the exact same spot:

Still wrong and strange

(The blue text is exactly where it is supposed to be, though.)

Can someone explain what I am doing wrong? I don’t understand why the node is put at the wrong place in either case.

Thanks in advance!

documentclass{article}
usepackage{tikz}
usetikzlibrary{calc,intersections}
begin{figure}
    centering
        begin{tikzpicture}
            draw[thick,dashed, name path=circ] (2,2) circle (2cm);
            
            begin{scope}[shift={(2,2)}]
                filldraw (165:2) node[left=3.5pt] (c) {large $c$} circle (3pt);
                filldraw (225:2) node[below=3.5pt] (b) {large $b$} circle (3pt);
                %filldraw (135:2) node[above=3.5pt] (a) {large $a$} circle (3pt);
            end{scope}  
            
            %path[shorten >=-0.5cm,-, name path= path1] let p1=($ (a) !.5! (b) $) in (2,2) -- ($(p1)+(5,0)$);
            %draw[name intersections = {of =circ and path1}] (intersection-1) node[blue] (ab) {Large right};
            path[shorten <= -0.5cm,-, name path=path3] let p1=($ (b) !.5! (c) $) in (p1) edge[gray] (2,2);
            draw[name intersections={of=circ and path3}] (intersection-1) node (bc) {wrong};
        end{tikzpicture}
end{figure}
end{document}

One Answer

First of make sure your MWE actually compiles, here begin{document} and the tikz lib calc are missing.

Secondly, the problem here is that in path[shorten <= -0.5cm,-, name path=path3] the shorten part does not add to the length of the path (the part that can be used for calculations), it only adds to the displayed version. Thus the line segment used to calculate the intersection is completely inside the circle and you get an error about it not being found.

This seems to work

documentclass{standalone}
usepackage{tikz}
usetikzlibrary{intersections,calc}
begin{document}
begin{tikzpicture}
  draw[thick,dashed, name path=circ] (2,2) circle (2cm);
  
  begin{scope}[shift={(2,2)}]
    filldraw (165:2) node[left=3.5pt] (c) {large $c$} circle (3pt);
    filldraw (225:2) node[below=3.5pt] (b) {large $b$} circle (3pt);
    % filldraw (135:2) node[above=3.5pt] (a) {large $a$} circle (3pt);
  end{scope}  
  
  % path[shorten >=-0.5cm,-, name path= path1] let p1=($ (a) !.5! (b) $) in (2,2) -- ($(p1)+(5,0)$);
  % draw[name intersections = {of =circ and path1}] (intersection-1) node[blue] (ab) {Large right};
  % path[shorten <= -0.5cm,-, name path=path3] let p1=($
  % (b) !.5! (c) $) in (p1) edge[gray] (2,2);
  
  coordinate (d) at ($(b) !.5! (c) $);
  coordinate (o) at (2,2);
  draw[name path=path3] (o) -- ($(o)!1.5!(d)$);
  draw[name intersections={of=circ and path3,by=e}] (e) node (bc) {wrong};
end{tikzpicture}
end{document}

I switched to the standallone class as it is more suitable for this type of question. Also removed the figure env as it is not relevant to this question.

Correct answer by daleif on December 14, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP