Tikz: Perspektivisches Zeichnen

Tikz: Perspektivisches Zeichnen

Ich arbeite daran, einen Strahl perspektivisch zu zeichnen. Ich habe einen Punkt, den ich als perspektivischen Punkt verwenden möchte (10, 3). Wie könnte ich entlang dieser Linie zeichnen? Betrachten Sie beispielsweise

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\draw (0, 0) rectangle (1cm, 1cm);
% I want to draw a 2cm line from (1cm, 0) along the ray that goes to my vanishing point
\end{tikzpicture}
\end{document}
  1. Ich könnte das Problem festlegen \pgfmathsetmacro\myangle{atan(3/10)}und verwenden\usetikzlibrary{calc}\draw (1cm, 0) -- ++(\myangle:2cm);
  2. Ich habe es mit der Ausgabe versucht \def\myangle{tan(3/10)}, aber das funktioniert überhaupt nicht.
  3. Oder ich könnte scopedie Linie verwenden und \draw (1cm, 0) -- (2cm, 0);um den gewünschten Winkel drehen.

Nachdem ich @PeterGrill repariert hatte tan, atanwurde mir klar, dass es ein Problem mit dem Zeichnen bis zum Fluchtpunkt gibt. Es (0, 0)würde nur auf der Linie mit Winkel liegen atan(3/10). Wie kann ich Anpassungen für die anderen Punkte vornehmen? Ich weiß, dass ich die Mathematik herausfinden könnte, aber kann LaTeX dies stattdessen handhaben?

Antwort1

Vielleicht habe ich die Frage falsch verstanden (passiert mir in letzter Zeit), aber vielleicht suchen Sie

\usetikzlibrary{calc}
..
\coordinate (vanishingpoint) at (10,3);
\draw (1,0) -- ($(1,0)!2cm!(vanishingpoint)$);

Antwort2

Eine weitere Alternative dazu tikz-3dplotbietet noch mehr Spaß.

  1. Stellen Sie das xyz-Koordinatensystem auf das xy-Koordinatensystem ein, indem Sie\tdplotsetmaincoords{90}{90}
  2. Zeichnen Sie zunächst ein großes Quadrat.
  3. Bestimmen Sie den Fluchtpunkt (X) in der Mitte des Quadrats.
  4. Verwenden Sie calc, um die Koordinaten einer kleineren Box über zu bestimmen, ($(d\i)!\s!(X)$)die erfordert calc.
  5. Wechseln Sie zurück zur XYZ-Koordinate über \tdplotsetmaincoords{70}{120}und viele andere verfügbare Ansichtswinkel.
  6. Der Code ist unten angegeben.

Bildbeschreibung hier eingeben

Code

\documentclass[border=1cm,varwidth]{standalone}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usetikzlibrary{shapes,calc,positioning}
\tdplotsetmaincoords{90}{90}

% decide the focus at distance f from the square, like (10,3) of the OP
\def\f{-8}    % try,10 etc

% determine the location of the smaller box
\def\s{0.7}   % 0<s<1

\begin{document}

\begin{tikzpicture}[scale=2, tdplot_main_coords,axis/.style={->,dashed},thick]
\draw[axis] (3, 0, 0) -- (-3, 0, 0) node [right] {$X$};
\draw[axis] (0, 0, 0) -- (0, 3, 0) node [above] {$Y$};
\draw[axis] (0, 0, 0) -- (0, 0, 3) node [above] {$Z$};

\node[coordinate]  (d1) at (2,0,0){};
\node[coordinate]  (d2) at (2,2,0){};
\node[coordinate]  (d3) at (2,2,2){};
\node[coordinate]  (d4) at (2,0,2){};

\coordinate (X) at (\f,1,1);  % change -5 to sue one's needs via \f.

\foreach \i in {1,2,3,4} {
\node[coordinate]  (t\i) at ($(d\i)!\s!(X)$){};
}

% draw lines

\foreach \i in {1,2,3,4}{
\draw[color=blue] (d\i) --(X);
}
\draw [fill=yellow,opacity=1]   (t1)--(t2)--(t3)--(t4)--cycle;
\draw [fill=yellow,opacity=0.5] (d1)--(d2)--(d3)--(d4)--cycle;

\end{tikzpicture}

% Try different view angle/perspective
% view from x {90}{90}
% view from y {90}{0}
% view from z {0}{90}
% view from the first   quadrant {70}{120}
% view from the second  quadrant {120}{70}

\tdplotsetmaincoords{70}{120}

\begin{tikzpicture}[scale=2, tdplot_main_coords,axis/.style={->,dashed},thick]
\draw[axis] (3, 0, 0) -- (-3, 0, 0) node [right] {$X$};
\draw[axis] (0, 0, 0) -- (0, 3, 0) node [above] {$Y$};
\draw[axis] (0, 0, 0) -- (0, 0, 3) node [above] {$Z$};

\node[coordinate]  (d1) at (2,0,0){};
\node[coordinate]  (d2) at (2,2,0){};
\node[coordinate]  (d3) at (2,2,2){};
\node[coordinate]  (d4) at (2,0,2){};
\coordinate  (X)  at (\f,1,1);

\foreach \i in {1,2,3,4} {
\node[coordinate]  (t\i) at ($(d\i)!\s!(X)$){};
}

% draw lines    
\foreach \i in {1,2,3,4}{
\draw[color=blue] (d\i) node[above right] {\color{red} \tiny \i} --(X);
}
\draw [fill=yellow, opacity=0.5] (d1)--(d2)--(d3)--(d4)--cycle;
\draw [fill=yellow, opacity=0.5] (t1)--(t2)--(t3)--(t4)--cycle;
\end{tikzpicture}

\end{document}

Antwort3

Die roten und blauen Linien dienen lediglich dazu, den Fluchtpunkt anzuzeigen. Sie beginnen an jeder Koordinate des Rechtecks ​​und laufen am Fluchtpunkt zusammen (X). Mit A scopewird das Objekt 70 % des Weges zum Fluchtpunkt verschoben und auf 30 % seiner Originalgröße skaliert.

Bildbeschreibung hier eingeben

Anmerkungen:

  • Verpacken Sie die Anwendung des , um ein und das scopeanzuwenden .shiftscale

Code:

\documentclass[tikz, border=2pt]{standalone}
\begin{document}
\usetikzlibrary{calc}

\newcommand*{\DrawAlongVanashingPoint}[4][]{%
    % #1 = draw options
    % #2 = start point
    % #3 = distance from point
    % #4 = vanishing point
    \draw [#1] (#2) -- ($(#2)!#3!(#4)$);
}
\begin{tikzpicture}
\draw [fill=yellow] (0, 0) rectangle (1cm, 1cm);
% I want to draw a 2cm line from (1cm, 0) along the ray that goes to my vanishing point
\pgfmathsetmacro\myangle{atan(3/10)}
\draw [thin, red] (1cm, 0) -- ++(\myangle:2cm) coordinate (X);
\draw [thin, red] (1,1) -- (X);
\draw [thin, red] (0,1) -- (X);
\draw [thin, red] (0,0) -- (X);


\DrawAlongVanashingPoint[thin, blue]{1,1}{0.7}{X};
\DrawAlongVanashingPoint[thin, blue]{0,1}{0.7}{X};
\DrawAlongVanashingPoint[thin, blue]{0,0}{0.7}{X};
\DrawAlongVanashingPoint[thin, blue]{1,0}{0.7}{X};

%\draw [fill=white](0, 0) rectangle (1cm, 1cm);% to hide the vanishing lines


\coordinate (ShiftPoint) at ($(0,0)!0.7!(X)$);
\begin{scope}[shift={(ShiftPoint)}, scale=0.3]
    \draw [fill=yellow] (0, 0) rectangle (1cm, 1cm);
\end{scope}


\end{tikzpicture}
\end{document}

verwandte Informationen