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). A는 scope객체를 소실점까지의 70%로 변환하고 객체의 크기를 원래 크기의 30%로 조정하는 데 사용됩니다.

여기에 이미지 설명을 입력하세요

노트:

  • 의 애플리케이션을 패키징하여 scopea shift및 를 적용합니다 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}

관련 정보