
私は遠近法で梁を描いています。遠近法の点として使いたい点があります(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
- を介して xyz 座標に戻り
\tdplotsetmaincoords{70}{120}
、他のさまざまなビュー角度も利用できます。 - コードは下記に示します。
コード
\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% に拡大するために使用されます。
ノート:
- および
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}