我正在绘制透视梁。我有一个点,我想将其用作透视点(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}
- 我可以设置
\pgfmathsetmacro\myangle{atan(3/10)}
并使用\usetikzlibrary{calc}
问题\draw (1cm, 0) -- ++(\myangle:2cm);
我已经尝试发行,\def\myangle{tan(3/10)}
但根本不起作用。- 或者我可以使用并按预期角度
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
是提供更多有趣的东西。
- 通过以下方式将 xyz 坐标系设置为 xy 坐标系
\tdplotsetmaincoords{90}{90}
- 先画一个大正方形。
- 确定正方形中心的消失点 (X)。
- 使用通过 确定需要的
calc
较小框的坐标。($(d\i)!\s!(X)$)
calc
\tdplotsetmaincoords{70}{120}
通过多种其他可用不同视角切换回 xyz 坐标 。- 下面给出代码。
代码
\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
以应用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}