2

In the following code, a box is rendered with perspective. I would like the ratio of the dimensions to be 3:4:12. The sides going into the page should be the shortest.

How do I draw the same box with the side going across the page parallel to the top and bottom edges of the page?

\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}
  • It would be better if you added the link to the answer of Jan Hlavacek as you said in your previous question here: https://tex.stackexchange.com/q/460537/138900 that you have adapted, that everyone understands the code more easily. – AndréC Nov 27 '18 at 19:43
  • I really think it would be appropriate to use Max' great answer, which is to the best of my knowledge the first post (at least on this site) that implements perspective drawing systematically in TikZ. –  Nov 27 '18 at 19:47
  • 1
    Technically, there is a difference between perspective and projection, with perspective being a much more difficult problem. (See https://tex.stackexchange.com/questions/312238/how-to-create-a-tikz-picture-with-a-non-infinite-distance-viewpoint/312959?s=1|21.7085#312959) – John Kormylo Nov 28 '18 at 05:01

1 Answers1

1

This is what you can achieve with Max' great answer. I understand that we disagree, but as AndréC points out, "the confrontation of ideas in science is essential". So, even if you do not like Max' great macros, or find them unnecessary, this answer is meant for others having a similar question. IMHO Max' methods have superseded the older answer by Jan Hlavacek, which, at that time, was a great step in the right direction.

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

enter image description here

As you requested. The dimensions of the boxes are stored in the macros \boxX, \boxY and \boxZ. Of course getting the desired output here requires slightly more effort here since, in addition to the two angles defining the view (or rotation) you also have the perspective parameters that you need to adjust.

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

enter image description here

  • 1
    I will use the macros that Max encoded if I know how to edit them to get various boxes. Please post the code to get two boxes in one tikzpicture with sides in the ratio of the dimensions to be 3:4:12. In one view, one edge should be closest to the observer, and in the other view, one face should be closest to the observer. – A gal named Desire Dec 01 '18 at 16:36
  • Please post one of the boxes as it would be seen from an observer directly in front of it ... so that the sides of the front are parallel to the edges of the page. Also, include dashed lines indicating the edges of the box that are out of view of the observer ... – A gal named Desire Dec 02 '18 at 15:49
  • ... and one of each of the edges of different lengths labeled x, y, or z ... – A gal named Desire Dec 02 '18 at 15:50
  • ... and a dashed line for a diagonal of a face and have it labeled face diagonal ... – A gal named Desire Dec 02 '18 at 15:50
  • ... and a dashed line for a diagonal of the box and have itlabeled box diagonal. – A gal named Desire Dec 02 '18 at 15:51
  • @AgalnamedDesire I regret to tell you that I am not going to do this. This site is a question and answer site. I believe to have provided you with all the necessary information to answer your question. It is perfectly fine if you choose not to use the three-point-perspective coordinate system and resort to other methods. If you choose, however, to use Max (IMHO great) macros, please go ahead and try to adjust his answer or the above to your needs. In case you get stuck, you can still come back and ask a question. –  Dec 04 '18 at 03:59
  • I am not sure why you would refuse to make any such accommodation, especially when I specifically requested at least one view as would be observed by someone directly in front of one of the faces of the box in the original post. – A gal named Desire Dec 07 '18 at 17:16