TransWikia.com

Why are my TikZ intersections not exact?

TeX - LaTeX Asked by Peater de Xel on April 1, 2021

In a TikZ picture, I try to intersect an arc with a cubic bezier line. However, the calculated intersection points seem off — do you know why that is? Is this some sort of rounding error?

zoom on the intersection

documentclass{article}
usepackage{tikz}
usepackage[graphics, active, tightpage]{preview}
PreviewEnvironment{tikzpicture}

usetikzlibrary{arrows.meta}
usetikzlibrary{intersections}

begin{document}

begin{tikzpicture}[
    detector/.style={line width=0.5pt, color=gray, line cap=round},
    track/.style={line width=0.9pt, color=black, -{Latex[length=2mm]}},
    seed track/.style={track, color=blue},
    red dot/.style={red, opacity=0.3}
]

draw[detector, name path=L1] (0,20mm) arc[start angle=90, end angle=0, radius=20mm];
draw[detector, name path=L2] (0,30mm) arc[start angle=90, end angle=0, radius=30mm];
draw[detector, name path=L3] (0,50mm) arc[start angle=90, end angle=0, radius=50mm];

draw[seed track, name path=curler track, opacity=0.6] (0,0) .. controls (0,0) and (52mm, 8mm) .. (21mm, 62mm);

fill[red dot, name intersections={of=L3 and curler track}](intersection-1) circle (1pt);
fill[red dot, name intersections={of=L2 and curler track}](intersection-1) circle (1pt);
fill[red dot, name intersections={of=L1 and curler track}](intersection-1) circle (1pt);

end{tikzpicture}

end{document}

One Answer

This is because adding a "quick" arrow distorts the path. Fixing the problem is as simple as loading the bending library, see p. 204 of the pgfmanual version 3.1.8b:

enter image description here

documentclass{article}
usepackage{tikz}
usepackage[graphics, active, tightpage]{preview}
PreviewEnvironment{tikzpicture}

usetikzlibrary{arrows.meta}
usetikzlibrary{bending}
usetikzlibrary{intersections}

begin{document}

begin{tikzpicture}[
    detector/.style={line width=0.5pt, color=gray, line cap=round},
    track/.style={line width=0.9pt, color=black, -{Latex[length=2mm]}},
    seed track/.style={track, color=blue},
    red dot/.style={red, opacity=0.3}
]

draw[detector, name path=L1] (0,20mm) arc[start angle=90, end angle=0, radius=20mm];
draw[detector, name path=L2] (0,30mm) arc[start angle=90, end angle=0, radius=30mm];
draw[detector, name path=L3] (0,50mm) arc[start angle=90, end angle=0, radius=50mm];

draw[seed track, name path=curler track, opacity=0.6] (0,0) .. controls (0,0) and (52mm, 8mm) .. (21mm, 62mm);

fill[red dot, name intersections={of=L3 and curler track}](intersection-1) circle (1pt);
fill[red dot, name intersections={of=L2 and curler track}](intersection-1) circle (1pt);
fill[red dot, name intersections={of=L1 and curler track}](intersection-1) circle (1pt);

end{tikzpicture}

end{document}

enter image description here

To have an explicit comparison, let us quickly add a quick arrow.

documentclass{article}
usepackage{tikz}
usepackage[graphics, active, tightpage]{preview}
PreviewEnvironment{tikzpicture}

usetikzlibrary{arrows.meta}
usetikzlibrary{bending}
usetikzlibrary{intersections}

begin{document}

begin{tikzpicture}[
    detector/.style={line width=0.5pt, color=gray, line cap=round},
    track/.style={line width=0.9pt, color=black, -{Latex[length=2mm]}},
    seed track/.style={track, color=blue},
    red dot/.style={red, opacity=0.3}
]

draw[detector, name path=L1] (0,20mm) arc[start angle=90, end angle=0, radius=20mm];
draw[detector, name path=L2] (0,30mm) arc[start angle=90, end angle=0, radius=30mm];
draw[detector, name path=L3] (0,50mm) arc[start angle=90, end angle=0, radius=50mm];

draw[seed track, name path=curler track, opacity=0.6] (0,0) .. controls (0,0) and (52mm, 8mm) .. (21mm, 62mm);
draw[dashed,red,-{Latex[length=2mm,quick]}] (0,0) .. controls (0,0) and (52mm, 8mm) .. (21mm, 62mm);
fill[red dot, name intersections={of=L3 and curler track}](intersection-1) circle (1pt);
fill[red dot, name intersections={of=L2 and curler track}](intersection-1) circle (1pt);
fill[red dot, name intersections={of=L1 and curler track}](intersection-1) circle (1pt);

end{tikzpicture}

end{document}

enter image description here

As you can see, the "quick" curve is off, and matches the one you had in your example.

Needless to say that you could also bend the arrow if you load bending, but this is not central to the current question.

Correct answer by user237299 on April 1, 2021

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