在 TikZ 中绘制一个盒子 - 一个边比其他边更靠近观察者 - 带有透视(版本 2)

在 TikZ 中绘制一个盒子 - 一个边比其他边更靠近观察者 - 带有透视(版本 2)

在下面的代码中,一个盒子以透视方式呈现。我希望尺寸比例为 3:4:12。进入页面的边应该是最短的。

我如何绘制相同的框,使其侧面穿过页面并与页面的顶部和底部边缘平行?

\documentclass{amsart}

\usepackage{tikz}
\usetikzlibrary{calc,intersections}



\begin{document}


\begin{center}
\begin{tikzpicture}

%\clip (-3,-3) rectangle (3,3);
\coordinate (top_front) at (0,0);
\coordinate (bottom_front) at (0,-3);
\coordinate (top_right) at (15:2.5cm);
\coordinate (top_left) at (165:2.5cm);

%You can change the perspective by playing with the 5, 5, 15:
\coordinate (front_right) at ($(top_front)!3!(top_right)$);
\coordinate (front_left) at ($(top_front)!5!(top_left)$);
\coordinate (front_bottom) at ($(top_front)!6!(bottom_front)$);

\path[name path=bottom_right_path] (bottom_front) -- (front_right);   
\path[name path=right_back_path] (top_right) -- (front_bottom);
\path[name path=back_left_path] (bottom_front) -- (front_left);
\path[name path=left_back_path] (top_left) -- (front_bottom);
\path[name path=top_right_path] (top_left) -- (front_right);
\path[name path=top_left_path] (top_right) -- (front_left);

\coordinate[name intersections={of=bottom_right_path and right_back_path, by=back_right}];
\coordinate[name intersections={of=back_left_path and left_back_path, by=back_left}];
\coordinate[name intersections={of=top_right_path and top_left_path, by=top_back}];


%The bottom-back vertex of the cube is located.
\path[name path=bottom_left_path] (back_left) -- (front_right);
\path[name path=back_right_path] (back_right) -- (front_left);
\coordinate[name intersections={of=bottom_left_path and back_right_path, by=bottom_back}];
%
\draw[dashed] (back_left) -- (bottom_back);
\draw [dashed](back_right) -- (bottom_back);
\draw[dashed] (top_back) -- (bottom_back);



%A diagonal on a face of the box is labeled.
\path[draw,dashed] (top_left)--(bottom_front)node[midway, above, sloped, font=\scriptsize]{face diagonal};
\draw[dashed,blue] (back_right) -- (top_left)node[midway, sloped, above, font=\scriptsize]{box diagonal};



%\shade[right color=gray!10, left color=black!50, shading angle=105] (top_front) -- (bottom_front) -- (back_left) -- (top_left) -- cycle;
%\shade[left color=gray!10, right color=black!50, shading angle=75] (top_front) -- (bottom_front) -- (back_right) -- (top_right) -- cycle;
\begin{scope}
\clip (top_front) -- (top_right) -- (top_back) -- (top_left) -- cycle;
\shade[inner color = gray!5, outer color=black!50, shading=radial] (top_front) ellipse (3cm and 1.5cm);
\end{scope}

\draw (top_front) -- (bottom_front);
\draw (top_front) -- (top_right);
\draw (top_front) -- (top_left);
\draw (top_right) -- (back_right);
\draw (bottom_front) -- (back_right);
\draw (top_left) -- (back_left);
\draw (bottom_front) -- (back_left);
\draw (top_back) -- (top_right);
\draw (top_back) -- (top_left);



\end{tikzpicture}
\end{center}



\end{document}

答案1

你可以通过以下方式实现Max 的精彩回答。我明白我们意见不一,但正如 AndréC 指出的那样, “科学中思想的碰撞是必要的”。所以,即使你不喜欢 Max 的出色宏,或者觉得它们没有必要,这个答案也适用于其他有类似问题的人。在我看来,Max 的方法已经取代了较早的答案由 Jan Hlavacek 发起,这在当时是朝着正确方向迈出的一大步。

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{tikz-3dplot}
\usepgfmodule{nonlineartransformations}
% Max magic https://tex.stackexchange.com/a/447120/121799
\makeatletter 
% the first part is not in use here
\def\tikz@scan@transform@one@point#1{%
  \tikz@scan@one@point\pgf@process#1%
  \pgf@pos@transform{\pgf@x}{\pgf@y}}
\tikzset{%
  grid source opposite corners/.code args={#1and#2}{%
   \pgfextract@process\tikz@transform@source@southwest{%
     \tikz@scan@transform@one@point{#1}}%
   \pgfextract@process\tikz@transform@source@northeast{%
     \tikz@scan@transform@one@point{#2}}%
  },
  grid target corners/.code args={#1--#2--#3--#4}{%
   \pgfextract@process\tikz@transform@target@southwest{%
     \tikz@scan@transform@one@point{#1}}%
   \pgfextract@process\tikz@transform@target@southeast{%
     \tikz@scan@transform@one@point{#2}}%
   \pgfextract@process\tikz@transform@target@northeast{%
     \tikz@scan@transform@one@point{#3}}%
   \pgfextract@process\tikz@transform@target@northwest{%
     \tikz@scan@transform@one@point{#4}}%
  }
}

\def\tikzgridtransform{%
  \pgfextract@process\tikz@current@point{}%
  \pgf@process{%
    \pgfpointdiff{\tikz@transform@source@southwest}%
      {\tikz@transform@source@northeast}%
  }%
  \pgf@xc=\pgf@x\pgf@yc=\pgf@y%
  \pgf@process{%
    \pgfpointdiff{\tikz@transform@source@southwest}{\tikz@current@point}%
  }%
  \pgfmathparse{\pgf@x/\pgf@xc}\let\tikz@tx=\pgfmathresult%
  \pgfmathparse{\pgf@y/\pgf@yc}\let\tikz@ty=\pgfmathresult%
  %
  \pgfpointlineattime{\tikz@ty}{%
    \pgfpointlineattime{\tikz@tx}{\tikz@transform@target@southwest}%
      {\tikz@transform@target@southeast}}{%
    \pgfpointlineattime{\tikz@tx}{\tikz@transform@target@northwest}%
      {\tikz@transform@target@northeast}}%
}

% Initialize H matrix for perspective view
\pgfmathsetmacro\H@tpp@aa{1}\pgfmathsetmacro\H@tpp@ab{0}\pgfmathsetmacro\H@tpp@ac{0}%\pgfmathsetmacro\H@tpp@ad{0}
\pgfmathsetmacro\H@tpp@ba{0}\pgfmathsetmacro\H@tpp@bb{1}\pgfmathsetmacro\H@tpp@bc{0}%\pgfmathsetmacro\H@tpp@bd{0}
\pgfmathsetmacro\H@tpp@ca{0}\pgfmathsetmacro\H@tpp@cb{0}\pgfmathsetmacro\H@tpp@cc{1}%\pgfmathsetmacro\H@tpp@cd{0}
\pgfmathsetmacro\H@tpp@da{0}\pgfmathsetmacro\H@tpp@db{0}\pgfmathsetmacro\H@tpp@dc{0}%\pgfmathsetmacro\H@tpp@dd{1}

%Initialize H matrix for main rotation
\pgfmathsetmacro\H@rot@aa{1}\pgfmathsetmacro\H@rot@ab{0}\pgfmathsetmacro\H@rot@ac{0}%\pgfmathsetmacro\H@rot@ad{0}
\pgfmathsetmacro\H@rot@ba{0}\pgfmathsetmacro\H@rot@bb{1}\pgfmathsetmacro\H@rot@bc{0}%\pgfmathsetmacro\H@rot@bd{0}
\pgfmathsetmacro\H@rot@ca{0}\pgfmathsetmacro\H@rot@cb{0}\pgfmathsetmacro\H@rot@cc{1}%\pgfmathsetmacro\H@rot@cd{0}
%\pgfmathsetmacro\H@rot@da{0}\pgfmathsetmacro\H@rot@db{0}\pgfmathsetmacro\H@rot@dc{0}\pgfmathsetmacro\H@rot@dd{1}

\pgfkeys{
    /three point perspective/.cd,
        p/.code args={(#1,#2,#3)}{
            \pgfmathparse{int(round(#1))}
            \ifnum\pgfmathresult=0\else
                \pgfmathsetmacro\H@tpp@ba{#2/#1}
                \pgfmathsetmacro\H@tpp@ca{#3/#1}
                \pgfmathsetmacro\H@tpp@da{ 1/#1}
                \coordinate (vp-p) at (#1,#2,#3);
            \fi
        },
        q/.code args={(#1,#2,#3)}{
            \pgfmathparse{int(round(#2))}
            \ifnum\pgfmathresult=0\else
                \pgfmathsetmacro\H@tpp@ab{#1/#2}
                \pgfmathsetmacro\H@tpp@cb{#3/#2}
                \pgfmathsetmacro\H@tpp@db{ 1/#2}
                \coordinate (vp-q) at (#1,#2,#3);
            \fi
        },
        r/.code args={(#1,#2,#3)}{
            \pgfmathparse{int(round(#3))}
            \ifnum\pgfmathresult=0\else
                \pgfmathsetmacro\H@tpp@ac{#1/#3}
                \pgfmathsetmacro\H@tpp@bc{#2/#3}
                \pgfmathsetmacro\H@tpp@dc{ 1/#3}
                \coordinate (vp-r) at (#1,#2,#3);
            \fi
        },
        coordinate/.code args={#1,#2,#3}{
           \pgfmathsetmacro\tpp@x{#1} %<- Max' fix
            \pgfmathsetmacro\tpp@y{#2}
            \pgfmathsetmacro\tpp@z{#3}
        },
}

\tikzset{
    view/.code 2 args={
        \pgfmathsetmacro\rot@main@theta{#1}
        \pgfmathsetmacro\rot@main@phi{#2}
        % Row 1
        \pgfmathsetmacro\H@rot@aa{cos(\rot@main@phi)}
        \pgfmathsetmacro\H@rot@ab{sin(\rot@main@phi)}
        \pgfmathsetmacro\H@rot@ac{0}
        % Row 2
        \pgfmathsetmacro\H@rot@ba{-cos(\rot@main@theta)*sin(\rot@main@phi)}
        \pgfmathsetmacro\H@rot@bb{cos(\rot@main@phi)*cos(\rot@main@theta)}
        \pgfmathsetmacro\H@rot@bc{sin(\rot@main@theta)}
        % Row 3
        \pgfmathsetmacro\H@m@ca{sin(\rot@main@phi)*sin(\rot@main@theta)}
        \pgfmathsetmacro\H@m@cb{-cos(\rot@main@phi)*sin(\rot@main@theta)}
        \pgfmathsetmacro\H@m@cc{cos(\rot@main@theta)}
        % Set vector values
        \pgfmathsetmacro\vec@x@x{\H@rot@aa}
        \pgfmathsetmacro\vec@y@x{\H@rot@ab}
        \pgfmathsetmacro\vec@z@x{\H@rot@ac}
        \pgfmathsetmacro\vec@x@y{\H@rot@ba}
        \pgfmathsetmacro\vec@y@y{\H@rot@bb}
        \pgfmathsetmacro\vec@z@y{\H@rot@bc}
        % Set pgf vectors
        \pgfsetxvec{\pgfpoint{\vec@x@x cm}{\vec@x@y cm}}
        \pgfsetyvec{\pgfpoint{\vec@y@x cm}{\vec@y@y cm}}
        \pgfsetzvec{\pgfpoint{\vec@z@x cm}{\vec@z@y cm}}
    },
}

\tikzset{
    perspective/.code={\pgfkeys{/three point perspective/.cd,#1}},
    perspective/.default={p={(15,0,0)},q={(0,15,0)},r={(0,0,50)}},
}

\tikzdeclarecoordinatesystem{three point perspective}{
    \pgfkeys{/three point perspective/.cd,coordinate={#1}}
    \pgfmathsetmacro\temp@p@w{\H@tpp@da*\tpp@x + \H@tpp@db*\tpp@y + \H@tpp@dc*\tpp@z + 1}
    \pgfmathsetmacro\temp@p@x{(\H@tpp@aa*\tpp@x + \H@tpp@ab*\tpp@y + \H@tpp@ac*\tpp@z)/\temp@p@w}
    \pgfmathsetmacro\temp@p@y{(\H@tpp@ba*\tpp@x + \H@tpp@bb*\tpp@y + \H@tpp@bc*\tpp@z)/\temp@p@w}
    \pgfmathsetmacro\temp@p@z{(\H@tpp@ca*\tpp@x + \H@tpp@cb*\tpp@y + \H@tpp@cc*\tpp@z)/\temp@p@w}
    \pgfpointxyz{\temp@p@x}{\temp@p@y}{\temp@p@z}
}
\tikzaliascoordinatesystem{tpp}{three point perspective}

\makeatother

\begin{document}
\foreach \X in {-87,-84,...,-3}
{  \tdplotsetmaincoords{70}{\X}
  \begin{tikzpicture}
  \path[use as bounding box] (-6,-2) rectangle (6,10);
  \begin{scope}[scale=6,font=\sffamily,
  view={\tdplotmaintheta}{\tdplotmainphi},
            perspective={
                p = {(4,0,1.5)},
                q = {(0,4,1.5)},
            }
  ]
  \begin{scope} % top face
   \draw[clip]   (tpp cs:0,0,1) coordinate (top_front)
  -- (tpp cs:1,0,1) coordinate (top_right)
   -- (tpp cs:1,1,1) coordinate (top_back)
   -- (tpp cs:0,1,1) coordinate (top_left) --
    cycle;
    \shade[inner color = gray!5, outer color=black!50, shading=radial] (top_front) ellipse (3cm and 1.5cm);
  \end{scope}
  % right face  
  \draw   (top_front) -- (top_right) -- (tpp cs:1,0,0) coordinate (bottom_right)
  -- (tpp cs:0,0,0)  coordinate (bottom_front) --   cycle;
  % top face  
  \draw   (top_front) -- (top_left) -- (tpp cs:0,1,0) coordinate (bottom_left)
  -- (bottom_front) --  cycle;
  % your midway coordinates with Max perspective coordinate system
  \coordinate (front_right) at (tpp cs:0.5,0,1);
  \coordinate (front_left) at (tpp cs:0,0.5,1);
  \coordinate (front_bottom) at (tpp cs:0,0,0.5);
  \end{scope}
  \end{tikzpicture}}
\end{document}

在此处输入图片描述

正如您所要求的。框的尺寸存储在宏\boxX\boxY和 中\boxZ。当然,在这里获得所需的输出需要稍微多一点的努力,因为除了定义视图(或旋转)的两个角度之外,您还需要调整透视参数。

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{tikz-3dplot}
\usepgfmodule{nonlineartransformations}
% Max magic https://tex.stackexchange.com/a/447120/121799
\makeatletter 
% the first part is not in use here
\def\tikz@scan@transform@one@point#1{%
  \tikz@scan@one@point\pgf@process#1%
  \pgf@pos@transform{\pgf@x}{\pgf@y}}
\tikzset{%
  grid source opposite corners/.code args={#1and#2}{%
   \pgfextract@process\tikz@transform@source@southwest{%
     \tikz@scan@transform@one@point{#1}}%
   \pgfextract@process\tikz@transform@source@northeast{%
     \tikz@scan@transform@one@point{#2}}%
  },
  grid target corners/.code args={#1--#2--#3--#4}{%
   \pgfextract@process\tikz@transform@target@southwest{%
     \tikz@scan@transform@one@point{#1}}%
   \pgfextract@process\tikz@transform@target@southeast{%
     \tikz@scan@transform@one@point{#2}}%
   \pgfextract@process\tikz@transform@target@northeast{%
     \tikz@scan@transform@one@point{#3}}%
   \pgfextract@process\tikz@transform@target@northwest{%
     \tikz@scan@transform@one@point{#4}}%
  }
}

\def\tikzgridtransform{%
  \pgfextract@process\tikz@current@point{}%
  \pgf@process{%
    \pgfpointdiff{\tikz@transform@source@southwest}%
      {\tikz@transform@source@northeast}%
  }%
  \pgf@xc=\pgf@x\pgf@yc=\pgf@y%
  \pgf@process{%
    \pgfpointdiff{\tikz@transform@source@southwest}{\tikz@current@point}%
  }%
  \pgfmathparse{\pgf@x/\pgf@xc}\let\tikz@tx=\pgfmathresult%
  \pgfmathparse{\pgf@y/\pgf@yc}\let\tikz@ty=\pgfmathresult%
  %
  \pgfpointlineattime{\tikz@ty}{%
    \pgfpointlineattime{\tikz@tx}{\tikz@transform@target@southwest}%
      {\tikz@transform@target@southeast}}{%
    \pgfpointlineattime{\tikz@tx}{\tikz@transform@target@northwest}%
      {\tikz@transform@target@northeast}}%
}

% Initialize H matrix for perspective view
\pgfmathsetmacro\H@tpp@aa{1}\pgfmathsetmacro\H@tpp@ab{0}\pgfmathsetmacro\H@tpp@ac{0}%\pgfmathsetmacro\H@tpp@ad{0}
\pgfmathsetmacro\H@tpp@ba{0}\pgfmathsetmacro\H@tpp@bb{1}\pgfmathsetmacro\H@tpp@bc{0}%\pgfmathsetmacro\H@tpp@bd{0}
\pgfmathsetmacro\H@tpp@ca{0}\pgfmathsetmacro\H@tpp@cb{0}\pgfmathsetmacro\H@tpp@cc{1}%\pgfmathsetmacro\H@tpp@cd{0}
\pgfmathsetmacro\H@tpp@da{0}\pgfmathsetmacro\H@tpp@db{0}\pgfmathsetmacro\H@tpp@dc{0}%\pgfmathsetmacro\H@tpp@dd{1}

%Initialize H matrix for main rotation
\pgfmathsetmacro\H@rot@aa{1}\pgfmathsetmacro\H@rot@ab{0}\pgfmathsetmacro\H@rot@ac{0}%\pgfmathsetmacro\H@rot@ad{0}
\pgfmathsetmacro\H@rot@ba{0}\pgfmathsetmacro\H@rot@bb{1}\pgfmathsetmacro\H@rot@bc{0}%\pgfmathsetmacro\H@rot@bd{0}
\pgfmathsetmacro\H@rot@ca{0}\pgfmathsetmacro\H@rot@cb{0}\pgfmathsetmacro\H@rot@cc{1}%\pgfmathsetmacro\H@rot@cd{0}
%\pgfmathsetmacro\H@rot@da{0}\pgfmathsetmacro\H@rot@db{0}\pgfmathsetmacro\H@rot@dc{0}\pgfmathsetmacro\H@rot@dd{1}

\pgfkeys{
    /three point perspective/.cd,
        p/.code args={(#1,#2,#3)}{
            \pgfmathparse{int(round(#1))}
            \ifnum\pgfmathresult=0\else
                \pgfmathsetmacro\H@tpp@ba{#2/#1}
                \pgfmathsetmacro\H@tpp@ca{#3/#1}
                \pgfmathsetmacro\H@tpp@da{ 1/#1}
                \coordinate (vp-p) at (#1,#2,#3);
            \fi
        },
        q/.code args={(#1,#2,#3)}{
            \pgfmathparse{int(round(#2))}
            \ifnum\pgfmathresult=0\else
                \pgfmathsetmacro\H@tpp@ab{#1/#2}
                \pgfmathsetmacro\H@tpp@cb{#3/#2}
                \pgfmathsetmacro\H@tpp@db{ 1/#2}
                \coordinate (vp-q) at (#1,#2,#3);
            \fi
        },
        r/.code args={(#1,#2,#3)}{
            \pgfmathparse{int(round(#3))}
            \ifnum\pgfmathresult=0\else
                \pgfmathsetmacro\H@tpp@ac{#1/#3}
                \pgfmathsetmacro\H@tpp@bc{#2/#3}
                \pgfmathsetmacro\H@tpp@dc{ 1/#3}
                \coordinate (vp-r) at (#1,#2,#3);
            \fi
        },
        coordinate/.code args={#1,#2,#3}{
           \pgfmathsetmacro\tpp@x{#1} %<- Max' fix
            \pgfmathsetmacro\tpp@y{#2}
            \pgfmathsetmacro\tpp@z{#3}
        },
}

\tikzset{
    view/.code 2 args={
        \pgfmathsetmacro\rot@main@theta{#1}
        \pgfmathsetmacro\rot@main@phi{#2}
        % Row 1
        \pgfmathsetmacro\H@rot@aa{cos(\rot@main@phi)}
        \pgfmathsetmacro\H@rot@ab{sin(\rot@main@phi)}
        \pgfmathsetmacro\H@rot@ac{0}
        % Row 2
        \pgfmathsetmacro\H@rot@ba{-cos(\rot@main@theta)*sin(\rot@main@phi)}
        \pgfmathsetmacro\H@rot@bb{cos(\rot@main@phi)*cos(\rot@main@theta)}
        \pgfmathsetmacro\H@rot@bc{sin(\rot@main@theta)}
        % Row 3
        \pgfmathsetmacro\H@m@ca{sin(\rot@main@phi)*sin(\rot@main@theta)}
        \pgfmathsetmacro\H@m@cb{-cos(\rot@main@phi)*sin(\rot@main@theta)}
        \pgfmathsetmacro\H@m@cc{cos(\rot@main@theta)}
        % Set vector values
        \pgfmathsetmacro\vec@x@x{\H@rot@aa}
        \pgfmathsetmacro\vec@y@x{\H@rot@ab}
        \pgfmathsetmacro\vec@z@x{\H@rot@ac}
        \pgfmathsetmacro\vec@x@y{\H@rot@ba}
        \pgfmathsetmacro\vec@y@y{\H@rot@bb}
        \pgfmathsetmacro\vec@z@y{\H@rot@bc}
        % Set pgf vectors
        \pgfsetxvec{\pgfpoint{\vec@x@x cm}{\vec@x@y cm}}
        \pgfsetyvec{\pgfpoint{\vec@y@x cm}{\vec@y@y cm}}
        \pgfsetzvec{\pgfpoint{\vec@z@x cm}{\vec@z@y cm}}
    },
}

\tikzset{
    perspective/.code={\pgfkeys{/three point perspective/.cd,#1}},
    perspective/.default={p={(15,0,0)},q={(0,15,0)},r={(0,0,50)}},
}

\tikzdeclarecoordinatesystem{three point perspective}{
    \pgfkeys{/three point perspective/.cd,coordinate={#1}}
    \pgfmathsetmacro\temp@p@w{\H@tpp@da*\tpp@x + \H@tpp@db*\tpp@y + \H@tpp@dc*\tpp@z + 1}
    \pgfmathsetmacro\temp@p@x{(\H@tpp@aa*\tpp@x + \H@tpp@ab*\tpp@y + \H@tpp@ac*\tpp@z)/\temp@p@w}
    \pgfmathsetmacro\temp@p@y{(\H@tpp@ba*\tpp@x + \H@tpp@bb*\tpp@y + \H@tpp@bc*\tpp@z)/\temp@p@w}
    \pgfmathsetmacro\temp@p@z{(\H@tpp@ca*\tpp@x + \H@tpp@cb*\tpp@y + \H@tpp@cc*\tpp@z)/\temp@p@w}
    \pgfpointxyz{\temp@p@x}{\temp@p@y}{\temp@p@z}
}
\tikzaliascoordinatesystem{tpp}{three point perspective}

\makeatother

\begin{document}
\tdplotsetmaincoords{70}{-70}
  \begin{tikzpicture}
  \pgfmathsetmacro{\boxX}{0.3}
  \pgfmathsetmacro{\boxY}{0.4}
  \pgfmathsetmacro{\boxZ}{1.2}
  \begin{scope}[scale=6,font=\sffamily,
  view={\tdplotmaintheta}{\tdplotmainphi},
            perspective={
                p = {(4,0,1.5)},
                q = {(0,4,1.5)},
            }
  ]
  \begin{scope} % top face
   \draw[clip]   (tpp cs:0,0,\boxZ) coordinate (top_front)
  -- (tpp cs:\boxX,0,\boxZ) coordinate (top_right)
   -- (tpp cs:\boxX,\boxY,\boxZ) coordinate (top_back)
   -- (tpp cs:0,\boxY,\boxZ) coordinate (top_left) --
    cycle;
    \shade[inner color = gray!5, outer color=black!50, shading=radial] 
    (top_front) ellipse (3cm and 1.5cm);
  \end{scope}
  % right face  
  \draw   (top_front) -- (top_right) -- (tpp cs:\boxX,0,0) coordinate (bottom_right)
  -- (tpp cs:0,0,0)  coordinate (bottom_front) --   cycle;
  % top face  
  \draw   (top_front) -- (top_left) -- (tpp cs:0,\boxY,0) coordinate (bottom_left)
  -- (bottom_front) --  cycle;
  \end{scope}
\tdplotsetmaincoords{70}{-90}
  \begin{scope}[xshift=6cm,scale=6,font=\sffamily,
  view={\tdplotmaintheta}{\tdplotmainphi},
            perspective={
                p = {(4,0,1.5)},
                q = {(0,4,1.5)},
            }
  ]
  \begin{scope} % top face
   \draw[clip]   (tpp cs:0,0,\boxZ) coordinate (top_front)
  -- (tpp cs:\boxX,0,\boxZ) coordinate (top_right)
   -- (tpp cs:\boxX,\boxY,\boxZ) coordinate (top_back)
   -- (tpp cs:0,\boxY,\boxZ) coordinate (top_left) --
    cycle;
    \shade[inner color = gray!5, outer color=black!50, shading=radial] 
    (top_front) ellipse (3cm and 1.5cm);
  \end{scope}
  % right face  
  \draw   (top_front) -- (top_right) -- (tpp cs:\boxX,0,0) coordinate (bottom_right)
  -- (tpp cs:0,0,0)  coordinate (bottom_front) --   cycle;
  % top face  
  \draw   (top_front) -- (top_left) -- (tpp cs:0,\boxY,0) coordinate (bottom_left)
  -- (bottom_front) --  cycle;
  \end{scope}
  \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容