
Ich verstehe nicht, wie es bei Verwendung von Polarkoordinaten mit einem angegebenen Winkel interpretiert wird. Ich habe in meinem MWE drei Beispiele vorbereitet:
\documentclass{article}
\usepackage{tikz} % TikZ and PGF picture
\usetikzlibrary{intersections}
\usetikzlibrary{calc}
\usetikzlibrary{positioning}
\usetikzlibrary{matrix,arrows,decorations.pathmorphing}
\usetikzlibrary{positioning}
\newdimen\XCoord
\newdimen\YCoord
\newcommand*{\ExtractCoordinate}[1]{\path (#1); \pgfgetlastxy{\XCoord}{\YCoord};}%
\begin{document}
\begin{figure}[htp]
\begin{tikzpicture}
\coordinate (A) at (0,0);
\coordinate (B) at (0,1);
\coordinate (C) at (1,1);
\node[left, color=blue] at (A) {A};
\node[left, color=blue] at (B) {B};
\node[right, color=blue] at (C) {C};
\draw (A) -- (B) -- (C);
\draw [color=cyan] let \p1=(A), \p2=(B), \p3=(C),
\n1={atan2(\y2-\y1,\x3-\x1)} in
(A) -- (\n1:2cm);
\ExtractCoordinate{B};
\node [below] at (1cm,-2cm) {B $(\XCoord,\YCoord)$};
\ExtractCoordinate{C};
\node [below] at (1cm,-2.5cm) {C $(\XCoord,\YCoord)$};
\end{tikzpicture}
\begin{tikzpicture}
\coordinate (A) at (-90.58205pt, 119.0348pt);
\coordinate (B) at (-90.58205pt, 133.26117pt);
\coordinate (C) at (-40.43698pt, 119.0348pt);
\node[left, color=blue] at (A) {A};
\node[left, color=blue] at (B) {B};
\node[right, color=blue] at (C) {C};
\draw (B) -- (A) -- (C);
\draw [color=cyan] let \p1=(A), \p2=(B), \p3=(C),
\n1={atan2(abs(\y2-\y1), abs(\x3-\x1))} in
(B) -- (74.161134732:2cm);
\draw[right, color=green] (B) -- (0:2cm);
\draw[right, color=red] (B) -- (45:2cm);
\ExtractCoordinate{B};
\node [below] at (1cm,-2cm) {B $(\XCoord,\YCoord)$};
\ExtractCoordinate{C};
\node [below] at (1cm,-2.5cm) {C $(\XCoord,\YCoord)$};
\end{tikzpicture}
\begin{tikzpicture}
\coordinate (A) at (2, 2);
\draw[right, color=green] (A) -- (0:2cm);
\draw[right, color=red] (A) -- (45:2cm);
\draw[right, color=blue] (A) -- (90:2cm);
\draw[right, color=black] (A) -- (74.161134732:2cm);
\end{tikzpicture}
\end{figure}
\end{document}
- erstes Beispiel: alles funktioniert einwandfrei.
- zweites Beispiel: Problem:
Im folgenden Befehl:
\draw [color=cyan] let \p1=(A), \p2=(B), \p3=(C), \n1={atan2(abs(\y2-\y1), abs(\x3-\x1))} in (B) -- (74.161134732:2cm);
Ich habe versucht, den Winkel zu berechnen, indem ich B mit C verbunden habe. Leider erfolglos. Ich dachte, dass die Funktion atan2 falsch funktioniert, also habe ich den Wert in der Variablen \n1 durch den manuell berechneten Winkel ersetzt, aber wieder habe ich die beiden Punkte nicht verbunden.
Ich bin zu dem Schluss gekommen, dass ich Polarkoordinaten nicht richtig verwenden kann, und habe daher versucht, alles im dritten Beispiel zu testen. Ich hatte erwartet, dass die grüne Linie horizontal sein würde, aber stattdessen ist sie vertikal.
Zur Veranschaulichung füge ich ein Bild an:
Können Sie mir erklären, wo ich falsch liege?
Antwort1
Es gibt zwei Fehler in Ihrem Code. Der erste ist mathematischer Natur: Die Argumente für die atan2
sind dieXund dann diej(Ich weiß, dass dies von Programm zu Programm unterschiedlich ist, also sollten Sie es immer überprüfen, wenn Sie atan2
Funktionen verwenden); außerdem sollten Sie, um den Winkel richtig zu erhalten, nicht die absoluten Werte nehmen, da dies zumindest den Quadranten ändert. Die korrekte Syntax für das atan2
in Ihrem zweiten Beispiel wäre also:
\draw [color=cyan] let \p1=(A), \p2=(B), \p3=(C),
\n1={atan2(\x3-\x1, \y2-\y1)} in
(B) -- (\n:2cm);
Der Grund, warum dies in Ihrem ersten Beispiel nicht angezeigt wird, liegt darin, dass beide Koordinatenausdrücke zu ausgewertet werden, 1
wobei die Reihenfolge keine Rolle spielt und die Annahme absoluter Werte nichts bewirkt.
Das oben genannte ist jedoch immer noch nicht richtig und dies ist der zweite Fehler. Sie zeichnen eine Linie von (B)
nach (\n:2cm)
. Die zweite Position wird in angegebenabsolutKoordinaten und so ist ein Punkt bei \n
Grad und2cm
vom Ursprung. Sie möchten, dass es von ist (B)
. Um das Koordinatensystem neu auszurichten, sollten Sie verwendenrelativKoordinaten. So (B) -- ++(\n:2cm)
bekommen Sie, was Sie wollen.
Auch dies wird im ersten Beispiel nicht angezeigt, da sich Ihr Punkt von Interesse (A)
in diesem Fall am Ursprung befindet, sodass relative und absolute Koordinaten dasselbe Ergebnis liefern.
Dies ist der gleiche Fehler wie in Ihrem dritten Beispiel. Die Koordinate (0:2cm)
wird (2,0)
, die vertikal nach unten von (A)
(befindet sich bei (2,2)
) verläuft. Um eine horizontale Linie zu erhalten, müssen Sie sie relativieren: ++(0:2cm)
.
Vollständiger Code:
\documentclass{article}
\usepackage{tikz} % TikZ and PGF picture
\usetikzlibrary{intersections}
\usetikzlibrary{calc}
\usetikzlibrary{positioning}
\usetikzlibrary{matrix,arrows,decorations.pathmorphing}
\usetikzlibrary{positioning}
\newdimen\XCoord
\newdimen\YCoord
\newcommand*{\ExtractCoordinate}[1]{\path (#1);
\pgfgetlastxy{\XCoord}{\YCoord};}%
\begin{document}
\begin{figure}[htp]
\begin{tikzpicture}
\coordinate (A) at (0,0);
\coordinate (B) at (0,1);
\coordinate (C) at (1,1);
\node[left, color=blue] at (A) {A};
\node[left, color=blue] at (B) {B};
\node[right, color=blue] at (C) {C};
\draw (A) -- (B) -- (C);
\draw [color=cyan] let \p1=(A), \p2=(B), \p3=(C),
\n1={atan2(\y2-\y1,\x3-\x1)} in
(A) -- (\n1:2cm);
\ExtractCoordinate{B};
\node [below] at (1cm,-2cm) {B $(\XCoord,\YCoord)$};
\ExtractCoordinate{C};
\node [below] at (1cm,-2.5cm) {C $(\XCoord,\YCoord)$};
\end{tikzpicture}
\begin{tikzpicture}
\coordinate (A) at (-90.58205pt, 119.0348pt);
\coordinate (B) at (-90.58205pt, 133.26117pt);
\coordinate (C) at (0pt, 119.0348pt);
\node[left, color=blue] at (A) {A};
\node[left, color=blue] at (B) {B};
\node[right, color=blue] at (C) {C};
\draw (B) -- (A) -- (C);
\draw [color=cyan] let \p1=(A), \p2=(B), \p3=(C),
\n1={atan2(\x3-\x1,\y1-\y2)} in
(B) -- ++(\n1:4cm);
\draw[right, color=green] (B) -- ++(0:2cm);
\draw[right, color=red] (B) -- ++(45:2cm);
\ExtractCoordinate{B};
\node [below] at (1cm,-2cm) {B $(\XCoord,\YCoord)$};
\ExtractCoordinate{C};
\node [below] at (1cm,-2.5cm) {C $(\XCoord,\YCoord)$};
\end{tikzpicture}
\begin{tikzpicture}
\coordinate (A) at (2, 2);
\draw[right, color=green] (A) -- ++(0:2cm);
\draw[right, color=red] (A) -- ++(45:2cm);
\draw[right, color=blue] (A) -- ++(90:2cm);
\draw[right, color=black] (A) -- ++(74.161134732:2cm);
\end{tikzpicture}
\end{figure}
\end{document}
Ergebnis: