
Warum führt die Koordinatentransformation im folgenden Beispiel zu einer falsch berechneten Position für E
?
\documentclass[border=4pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{tkz-euclide}
\usetkzobj{all}
\begin{document}
\begin{tikzpicture}[x=0.5in, y=0.5in]%% <-- calculation of "E" is incorrect
%%\begin{tikzpicture}%% <-- calculation of "E" is correct
\coordinate (Q) at (0,0);
\coordinate (A) at (-170:1);
\coordinate (B) at (-70:1);
\coordinate (C) at (-20:1);
\coordinate (D) at (50:1);
\tkzInterLL(A,C)(B,D)
\tkzGetPoint{E}
\draw (A) -- (C);
\draw (B) -- (D);
\node[circle,fill,inner sep=1pt] at (E) {};
\end{tikzpicture}
\end{document}
Antwort1
Dies liegt daran, dass der Autor von tkz-euclide
annimmt, dass die Einheitsvektoren jeweils sind 1cm
. Sie können sehen, was passiert, indem Sie sich die Definition von ansehen \tkz@InterLL
(ein privates Makro, das von verwendet wird \tkzInterLL
und den Schnittpunkt zurückgibt, der in coordinate
E
von gespeichert wird \tkzGetPoint{E}
... puh!).
Hier ist es:
\def\tkz@InterLL(#1,#2)(#3,#4)#5{%
%\path (intersection of #1--#2 and #3--#4) coordinate(#5);%
\pgfextractx{\pgf@x}{\pgfpointanchor{#1}{center}}
\pgfextracty{\pgf@y}{\pgfpointanchor{#1}{center}}
\tkz@ax\pgf@x %
\tkz@ay\pgf@y %
\pgfextractx{\pgf@x}{\pgfpointanchor{#2}{center}}
\pgfextracty{\pgf@y}{\pgfpointanchor{#2}{center}}
\tkz@bx\pgf@x %
\tkz@by\pgf@y %
\pgfextractx{\pgf@x}{\pgfpointanchor{#3}{center}}
\pgfextracty{\pgf@y}{\pgfpointanchor{#3}{center}}
\tkz@cx\pgf@x %
\tkz@cy\pgf@y %
\pgfextractx{\pgf@x}{\pgfpointanchor{#4}{center}}
\pgfextracty{\pgf@y}{\pgfpointanchor{#4}{center}}
\tkz@dx\pgf@x %
\tkz@dy\pgf@y %
\FPeval\tkz@deltax{\pgf@sys@tonumber{\tkz@ax}-\pgf@sys@tonumber{\tkz@bx}}
\FPdiv\tkz@deltax{\tkz@deltax}{28.45274}
\FPeval\tkz@deltaxx{\pgf@sys@tonumber{\tkz@cx}-\pgf@sys@tonumber{\tkz@dx}}
\FPdiv\tkz@deltaxx{\tkz@deltaxx}{28.45274}
\FPeval\tkz@deltay{\pgf@sys@tonumber{\tkz@ay}-\pgf@sys@tonumber{\tkz@by}}
\FPdiv\tkz@deltay{\tkz@deltay}{28.45274}
\FPeval\tkz@deltayy{\pgf@sys@tonumber{\tkz@cy}-\pgf@sys@tonumber{\tkz@dy}}
\FPdiv\tkz@deltayy{\tkz@deltayy}{28.45274}
\FPeval\tkz@deltaxy{(\pgf@sys@tonumber{\tkz@ax}*\pgf@sys@tonumber{\tkz@by})-(\pgf@sys@tonumber{\tkz@ay}*\pgf@sys@tonumber{\tkz@bx})}
\FPdiv\tkz@deltaxy{\tkz@deltaxy}{28.45274}
\FPdiv\tkz@deltaxy{\tkz@deltaxy}{28.45274}
\FPeval\tkz@deltaxxyy{(\pgf@sys@tonumber{\tkz@cx}*\pgf@sys@tonumber{\tkz@dy})-(\pgf@sys@tonumber{\tkz@cy}*\pgf@sys@tonumber{\tkz@dx})}
\FPdiv\tkz@deltaxxyy{\tkz@deltaxxyy}{28.45274}
\FPdiv\tkz@deltaxxyy{\tkz@deltaxxyy}{28.45274}
\FPeval\tkz@div{(\tkz@deltax*\tkz@deltayy)-(\tkz@deltay*\tkz@deltaxx)}
\FPeval\tkz@numx{(\tkz@deltaxy*\tkz@deltaxx)-(\tkz@deltax*\tkz@deltaxxyy)}
\FPeval\tkz@numy{(\tkz@deltaxy*\tkz@deltayy)-(\tkz@deltay*\tkz@deltaxxyy)}
\FPdiv\tkz@xs{\tkz@numx}{\tkz@div}
\FPdiv\tkz@ys{\tkz@numy}{\tkz@div}
\FPround\tkz@xs{\tkz@xs}{5}
\FPround\tkz@ys{\tkz@ys}{5}
\path[coordinate](\tkz@xs,\tkz@ys) coordinate (#5);
}
Sehen Sie all die 28.45274
s in der Mitte? Das ist die Umrechnung einer angenommenen Einheitsvektorlänge von 1cm
in Einheiten von pt
zur späteren Rundung und Verwendung.
Versuchen wir also als Test, die Skala so zu definieren, dass sie in
äquivalent ist zu 1cm
:
\documentclass[border=4pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{tkz-euclide}
\usetkzobj{all}
\begin{document}
\begin{tikzpicture}[x=0.3937in, y=0.3937in] % works
%\begin{tikzpicture}[x=0.3937in, y=1cm] % works
%\begin{tikzpicture}[x=1cm, y=0.3937in] % works
%\begin{tikzpicture}[x=1cm, y=1cm] % works
%\begin{tikzpicture} % works
\coordinate (Q) at (0,0);
\coordinate (A) at (-170:1);
\coordinate (B) at (-70:1);
\coordinate (C) at (-20:1);
\coordinate (D) at (50:1);
\tkzInterLL(A,C)(B,D)
\tkzGetPoint{E}
\draw (A) -- (C);
\draw (B) -- (D);
\node[circle,fill,inner sep=1pt] at (E) {};
\end{tikzpicture}
\end{document}
Jede dieser Linien liefert das richtige Ergebnis. Aber wenn ich x=0.5in
oder mache y=2cm
, wird der Punkt auf einer der Achsen falsch ausgerichtet sein. Und wenn beide Einheitsvektoren geändert werden, wird der Punkt auf beiden Achsen falsch ausgerichtet sein.
Kurz zusammengefasstWenn Sie verwenden tkz-euclide
, können Sie beliebige Einheitsvektoren verwenden, solange diese gleichwertig sind x=1cm, y=1cm
.