Tikz: dibujando en perspectiva

Tikz: dibujando en perspectiva

Estoy trabajando para dibujar una viga en perspectiva. Tengo mi punto que quiero usar como punto de perspectiva (10, 3). ¿Cuál sería la forma de trazar esta línea? Por ejemplo, considere

\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. Podría configurar \pgfmathsetmacro\myangle{atan(3/10)}y usar el \usetikzlibrary{calc}para emitir\draw (1cm, 0) -- ++(\myangle:2cm);
  2. Intenté emitir \def\myangle{tan(3/10)}pero esto no funciona en absoluto.
  3. O podría usar scopey rotar la línea \draw (1cm, 0) -- (2cm, 0);en el ángulo deseado.

Después de corregirlo tanen atan@PeterGrill, me di cuenta de que hay un problema al dibujar hasta el punto de fuga. Sólo (0, 0)estaría en la línea con ángulo atan(3/10). ¿Cómo se pueden hacer ajustes para los demás puntos? Sé que podría resolver los cálculos, pero ¿puede LaTeX manejar esto?

Respuesta1

Quizás entendí mal la pregunta (me pasa últimamente), pero quizás estés buscando

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

Respuesta2

Otra alternativa tikz-3dplotofrece cosas más divertidas.

  1. Establezca el sistema de coordenadas xyz en el sistema de coordenadas xy mediante\tdplotsetmaincoords{90}{90}
  2. Primero dibuja un cuadrado grande.
  3. Determine el punto de fuga (X) en el centro del cuadrado.
  4. Se utiliza calcpara determinar las coordenadas de una caja más pequeña mediante ($(d\i)!\s!(X)$)la que se requiere calc.
  5. Vuelva a las coordenadas xyz \tdplotsetmaincoords{70}{120}y muchos otros ángulos de visión diferentes disponibles.
  6. Código que se proporciona a continuación.

ingrese la descripción de la imagen aquí

Código

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

Respuesta3

Las líneas roja y azul son solo para mostrar el punto de fuga: comienzan en cada coordenada del rectángulo y convergen en el punto de fuga (X). A scopese utiliza para trasladar el objeto al 70% del camino hasta el punto de fuga y escalar el objeto al 30% de su tamaño original.

ingrese la descripción de la imagen aquí

Notas:

  • Empaquete la aplicación de scopepara aplicar a shifty scale.

Código:

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

información relacionada