TikZで透視図を描く
自力で計算する例
https://scrapbox.io/files/65b9e821f3e5af00246de646.svg
code:vanishing_points.tikz(tex)
% Under Creative Commons Attribution licence 3.0
% Author: Florian Lesaint
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
%%% Edit the following coordinate to change the shape of your
%%% cuboid
%% Vanishing points for perspective handling
\coordinate (P1) at (-7cm,1.5cm); % left vanishing point (To pick)
\coordinate (P2) at (8cm,1.5cm); % right vanishing point (To pick)
%% (A1) and (A2) defines the 2 central points of the cuboid
\coordinate (A1) at (0em,0cm); % central top point (To pick)
\coordinate (A2) at (0em,-2cm); % central bottom point (To pick)
%% (A3) to (A8) are computed given a unique parameter (or 2) .8
% You can vary .8 from 0 to 1 to change perspective on left side
\coordinate (A3) at ($(P1)!.8!(A2)$); % To pick for perspective
\coordinate (A4) at ($(P1)!.8!(A1)$);
% You can vary .8 from 0 to 1 to change perspective on right side
\coordinate (A7) at ($(P2)!.7!(A2)$);
\coordinate (A8) at ($(P2)!.7!(A1)$);
%% Automatically compute the last 2 points with intersections
\coordinate (A5) at
(intersection cs: first line={(A8) -- (P1)},
second line={(A4) -- (P2)});
\coordinate (A6) at
(intersection cs: first line={(A7) -- (P1)},
second line={(A3) -- (P2)});
%%% Depending of what you want to display, you can comment/edit
%%% the following lines
%% Possibly draw back faces
\fillgray!90 (A2) -- (A3) -- (A6) -- (A7) -- cycle; % face 6 \node at (barycentric cs:A2=1,A3=1,A6=1,A7=1) {\tiny f6};
\fillgray!50 (A3) -- (A4) -- (A5) -- (A6) -- cycle; % face 3 \node at (barycentric cs:A3=1,A4=1,A5=1,A6=1) {\tiny f3};
\fillgray!30 (A5) -- (A6) -- (A7) -- (A8) -- cycle; % face 4 \node at (barycentric cs:A5=1,A6=1,A7=1,A8=1) {\tiny f4};
%% Possibly draw front faces
% \fillorange (A1) -- (A8) -- (A7) -- (A2) -- cycle; % face 1 % \node at (barycentric cs:A1=1,A8=1,A7=1,A2=1) {\tiny f1};
\node at (barycentric cs:A1=1,A2=1,A3=1,A4=1) {\tiny f2};
\node at (barycentric cs:A1=1,A4=1,A5=1,A8=1) {\tiny f5};
%% Possibly draw front lines
% Possibly draw points
% (it can help you understand the cuboid structure)
\foreach \i in {1,2,...,8}
{
}
\end{tikzpicture}
\end{document}
座標系three point perspective(略記:tpp)が使えるようになる
code:use-perspective.tikz(tex)
\usetikzlibrary{perspective}
\begin{document}
\begin{tikzpicture}[
scale=1.3,
isometric view,
perspective={
p = {(8,0,-1)},
q = {(0,8,-1)}
}]
\draw fill=black (0,8,-1) coordinate (Q) circle (0.1em) nodebelow {\tiny q}; \drawfill=black (8,0,-1) coordinate (P) circle (0.1em) nodebelow {\tiny p}; \def\w{2};
\def\h{2};
\def\d{4};
\coordinate (A1) at (tpp cs:x=0,y=0,z=\h);
\coordinate (A2) at (tpp cs:x=0,y=0,z=0);
\coordinate (A3) at (tpp cs:x=0,y=\w,z=0);
\coordinate (A4) at (tpp cs:x=0,y=\w,z=\h);
\coordinate (A5) at (tpp cs:x=\d,y=\w,z=\h);
\coordinate (A6) at (tpp cs:x=\d,y=\w,z=0);
\coordinate (A7) at (tpp cs:x=\d,y=0,z=0);
\coordinate (A8) at (tpp cs:x=\d,y=0,z=\h);
(A5) -- (P)
(A6) -- (P)
(A7) -- (P)
(A8) -- (P)
(A3) -- (Q)
(A4) -- (Q)
(A5) -- (Q)
(A6) -- (Q);
\fillgray!90 (A2) -- (A3) -- (A6) -- (A7) -- cycle; % face 6 \node at (barycentric cs:A2=1,A3=1,A6=1,A7=1) {\tiny f6};
\fillgray!50 (A3) -- (A4) -- (A5) -- (A6) -- cycle; % face 3 \node at (barycentric cs:A3=1,A4=1,A5=1,A6=1) {\tiny f3};
\fillgray!30 (A5) -- (A6) -- (A7) -- (A8) -- cycle; % face 4 \node at (barycentric cs:A5=1,A6=1,A7=1,A8=1) {\tiny f4};
(A5) -- (A6)
(A3) -- (A6)
(A7) -- (A6);
\node at (barycentric cs:A1=1,A2=1,A3=1,A4=1) {\tiny f2};
\node at (barycentric cs:A1=1,A4=1,A5=1,A8=1) {\tiny f5};
(A1) -- (A2)
(A3) -- (A4)
(A7) -- (A8)
(A1) -- (A4)
(A1) -- (A8)
(A2) -- (A3)
(A2) -- (A7)
(A4) -- (A5)
(A8) -- (A5);
\end{tikzpicture}
\end{document}