TeX - LaTeX Asked by Mad Hatter on December 17, 2020
I aimed at drawing a square (using TikZ) with a red dot inside it, placed on the intersection of its diagonals:
And while the following method worked fine:
documentclass[12pt]{article}
usepackage{tikz}
begin{document}
begin{tikzpicture}
coordinate (a) at (0,0);
coordinate (b) at (1,1);
coordinate (c) at (1,0);
coordinate (d) at (0,1);
coordinate (i) at (intersection of a--b and c--d);
fill[red] (i) circle (2pt);
draw (0,0) rectangle (1,1);
end{tikzpicture}
end{document}
when I tried this solution which does not involve specification of the coordinates:
begin{tikzpicture}
coordinate (i) at (intersection of {(0,0)--(1,1)} and {(1,0)--(0,1)});
fill[red] (i) circle (2pt);
draw (0,0) rectangle (1,1);
end{tikzpicture}
the result was:
So I tried modifying the code to this:
begin{tikzpicture}
draw (0,0) rectangle (1,1);
coordinate (i) at (intersection of {(0,0)--(1,1)} and {(1,0)--(0,1)});
fill[red] (i) circle (2pt);
end{tikzpicture}
which resulted in the following error message:
! Package PGF Math Error: You asked me to calculate `1/0.0', but I cannot divide any number by zero.
And here’s the question – I do not understand why the codes above behave like that. What is the difference between computing the intersection point via defined coordinates and via points on the plane directly. Could you please explain this to me?
As per Ulrike's comment.
documentclass[convert]{standalone}
usepackage{tikz}
begin{document}
begin{tikzpicture}
coordinate (a) at (0,0);
coordinate (b) at (1,1);
coordinate (c) at (1,0);
coordinate (d) at (0,1);
coordinate (i) at (intersection of {0,0--1,1} and {1,0--0,1});
fill[red] (i) circle (2pt);
draw (0,0) rectangle (1,1);
end{tikzpicture}
end{document}
Answered by Roald on December 17, 2020
Although syntax used by Mad Hatter is still valid, it's and old syntax which is not anymore documented in TikZ 3.0. So, for completion, the a la TikZ 3.0 way to obtain similar results could be:
intersections
librarypath[name path=ac] (0,0)--(1,1);
...name intersections={of=ac and bd}
More information about intersections
library in 13.3.2 Intersections of arbitrary paths.
Complete code:
documentclass[12pt]{article}
usepackage{tikz}
usetikzlibrary{intersections}
begin{document}
begin{tikzpicture}
path[name path=ac] (0,0)--(1,1);
path[name path=bd] (1,0)--(0,1);
fill [red, name intersections={of=ac and bd}] (intersection-1) circle (2pt);
draw (0,0) rectangle (1,1);
end{tikzpicture}
end{document}
Answered by Ignasi on December 17, 2020
@UlrikeFischer -- @Ignasi -- Would this code be counted as okay
documentclass[12pt]{article}
usepackage{tikz}
%usetikzlibrary{intersections}
begin{document}
begin{tikzpicture}
path[] (0,0)--(1,1) node (A) [circle,fill, red,inner sep=0pt, pos=0.5,minimum size=4pt,text width=1pt] {};
path[] (1,0)--(0,1);
%fill [red, pos=0.5] (path=ac) circle (2pt);
draw (0,0) rectangle (1,1);
end{tikzpicture}
end{document}
Answered by js bibra on December 17, 2020
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP