Tikz:透視繪畫

Tikz:透視繪畫

我正在努力繪製透視梁。我有我的觀點,我想用它作為視角(10, 3)。沿著這條線畫的方法是什麼?例如,考慮

\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. 我可以設定\pgfmathsetmacro\myangle{atan(3/10)}並使用\usetikzlibrary{calc}來發出\draw (1cm, 0) -- ++(\myangle:2cm);
  2. 我嘗試過發布,\def\myangle{tan(3/10)}但這根本不起作用。
  3. 或者我可以使用並按預期角度scope旋轉該線。\draw (1cm, 0) -- (2cm, 0);

在修復tan@PeterGrill之後atan,我意識到繪製到消失點有問題。只(0, 0)需要加上角度就行了atan(3/10)。其他點如何調整?我知道我可以算出數學公式,但是 LaTeX 可以處理這個問題嗎?

答案1

可能是我誤解了這個問題(最近發生在我身上),但可能你正在尋找

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

答案2

另一個選擇tikz-3dplot提供了更多有趣的東西。

  1. 將 xyz 座標系設定為 xy 座標系:\tdplotsetmaincoords{90}{90}
  2. 先畫一個大正方形。
  3. 確定正方形中心的消失點 (X)。
  4. 用於calc透過 確定較小框的座標($(d\i)!\s!(X)$)需要calc
  5. \tdplotsetmaincoords{70}{120}透過和許多其他可用的不同視角切換回 xyz 座標 。
  6. 代碼如下。

在此輸入影像描述

程式碼

\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}

答案3

紅線和藍線只是為了顯示消失點——它們從矩形的每個座標開始,匯聚到消失點(X)。 Ascope用於將物件平移到消失點的 70%,並將物件縮放到其原始大小的 30%。

在此輸入影像描述

筆記:

  • scope打包申請 ashift和 的應用程式scale

代碼:

\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}

相關內容