2

I would like to project one of the 2D surfaces or faces of the 3D cuboid on to a plane, as indicated in the diagram follows. Kindly help me.

enter image description here

\documentclass[border=5pt]{standalone}
\usepackage{tikz} 
\usetikzlibrary{quotes,arrows.meta}
\begin{document}
\begin{tikzpicture}[every edge quotes/.append style={auto, ultra thick, text=black}]
\pgfmathsetmacro{\cubex}{5}
\pgfmathsetmacro{\cubey}{5}
\pgfmathsetmacro{\cubez}{5}
\draw [draw=black, every edge/.append style={draw=black, thick, densely dashed, 
opacity=.25},fill=blue!25,opacity=0.8]
(0,0,0) coordinate (o) -- ++(-\cubex,0,0) coordinate (a) -- ++(0,-\cubey,0) coordinate (b) edge 
coordinate [pos=1] (g) ++(0,0,-\cubez)  -- ++(\cubex,0,0) coordinate (c) -- cycle
(o) -- ++(0,0,-\cubez) coordinate (d) -- ++(0,-\cubey,0) coordinate (e) edge (g) -- (c) -- cycle
(o) -- (a) -- ++(0,0,-\cubez) coordinate (f) edge (g) -- (d) -- cycle;
\end{tikzpicture}
\begin{tikzpicture}
\draw (0,0) -- (5,5) -- (5,0) -- (0,-5) -- (0,0); 
\end{tikzpicture} 
\end{document}
rakatex
  • 489
  • 2
  • 13

1 Answers1

3

If you have properly installed a coordinate system, you can use

canvas is <planex planey> plane at <orth>=<coord>

from the 3d library. Here <planex planey> is something like xy or zx, and <orth> denotes the orthogonal direction (i.e. for xy it is z, for zx it is y and so on), and coord is the coordinate to the plane along the orthogonal direction. if you are using the (admittedly overkill) answer from your previous question, adding the stuff is as simple as saying

\begin{scope}[canvas is xz plane at y=\cubey/2]
 ...
\end{scope}

but clearly you do not all the details of this answer, e.g. a picture with 3d view from the perspective library will do.

\documentclass[tikz,border=5pt]{standalone}
\usepackage{tikzlings}
\usetikzlibrary{perspective,3d,fpu}
\makeatletter
\pgfmathdeclarefunction{screendepth}{3}{%
\begingroup%
\pgfkeys{/pgf/fpu,/pgf/fpu/output format=fixed}%
\pgfmathparse{%
((\the\pgf@yx/1cm)*(\the\pgf@zy/1cm)-(\the\pgf@yy/1cm)*(\the\pgf@zx/1cm))*(#1)+
((\the\pgf@zx/1cm)*(\the\pgf@xy/1cm)-(\the\pgf@xx/1cm)*(\the\pgf@zy/1cm))*(#2)+
((\the\pgf@xx/1cm)*(\the\pgf@yy/1cm)-(\the\pgf@yx/1cm)*(\the\pgf@xy/1cm))*(#3)}%
\pgfmathsmuggle\pgfmathresult\endgroup%
}%
\pgfmathdeclarefunction{totalthree}{3}{%
\pgfmathparse{#1+#2+#3}}
\pgfmathdeclarefunction{direction}{3}{%
\begingroup%
\pgfmathparse{int(#1==0)}%
\ifnum\pgfmathresult=1
 \pgfmathparse{int(#2==0)}%
 \ifnum\pgfmathresult=1
  \edef\pgfmathresult{z}%
 \else
  \edef\pgfmathresult{y}%
 \fi
\else
 \edef\pgfmathresult{x}%
\fi
\pgfmathsmuggle\pgfmathresult\endgroup%
}
\makeatother
\begin{document}
\begin{tikzpicture}[3d view={120}{15},line join=round,
    xy face/.style={fill=orange},yx face/.style={fill=yellow},
    xz face/.style={fill=blue},zx face/.style={fill=cyan},
    yz face/.style={fill=red},zy face/.style={fill=magenta}]    
\pgfmathsetmacro{\cubex}{5}
\pgfmathsetmacro{\cubey}{5}
\pgfmathsetmacro{\cubez}{5}
\begin{scope}[fill opacity=0.8,]
 \def\pft#1#2;{\edef\planex{\csname cube#1\endcsname}%
 \edef\planey{\csname cube#2\endcsname}}
 \foreach \X/\Y in {xy/{(0,0,1)},yx/{(0,0,-1)},xz/{(0,1,0)},zx/{(0,-1,0)},yz/{(1,0,0)},zy/{(-1,0,0)}}
 {\pgfmathsetmacro{\myproj}{screendepth\Y}
 \ifdim\myproj pt<0pt
 \pgfmathsetmacro{\mytot}{totalthree\Y}
 \pgfmathsetmacro{\mydir}{direction\Y}
 \edef\myshift{\csname cube\mydir\endcsname}
 \expandafter\pft\X;
 \begin{scope}[style/.expanded={canvas is \X\space plane at \mydir={\mytot*0.5*\myshift}}]
  \draw[dashed,style/.expanded=\X\space face]
   (-\planex/2,-\planey/2) rectangle (\planex/2,\planey/2);
 \end{scope}
 \fi}
 \foreach \X/\Y in {xy/{(0,0,1)},yx/{(0,0,-1)},xz/{(0,1,0)},zx/{(0,-1,0)},yz/{(1,0,0)},zy/{(-1,0,0)}}
 {\pgfmathsetmacro{\myproj}{screendepth\Y}
 \ifdim\myproj pt>0pt
 \pgfmathsetmacro{\mytot}{totalthree\Y}
 \pgfmathsetmacro{\mydir}{direction\Y}
 \edef\myshift{\csname cube\mydir\endcsname}
 \expandafter\pft\X;
 \begin{scope}[style/.expanded={canvas is \X\space plane at \mydir={\mytot*0.5*\myshift}}]
  \draw[style/.expanded=\X\space face]
   (-\planex/2,-\planey/2) rectangle (\planex/2,\planey/2);
 \end{scope}
 \fi}
\end{scope}
\begin{scope}[canvas is xz plane at y=\cubey/2]
 \draw (-2,-2) rectangle (2,2);
 \draw[thick] (0,0) circle[radius=1.5cm]
  (-0.8,-0.3) arc[start angle=-120,end angle=-60,radius={0.8/sin(30)}];
 \fill (-0.6,0.5) circle[radius=0.1] (0.6,0.5) circle[radius=0.1];
\end{scope}
\begin{scope}[canvas is yz plane at x=\cubex/2]
 \koala[scale=1.5,yshift=-1cm,fill opacity=1]
\end{scope}
\end{tikzpicture}
\end{document}

enter image description here

The koala is just for fun, to show that you can project pretty much anything that way, also external graphics or text, but make sure that you dial transform shape in the respective nodes (or scope) if you are doing that.

  • Schrödinger's cat thank you very much, but I want the entire surface to be project out say, I want to explode the surface alone in addition to the cuboid. – rakatex May 15 '20 at 21:00
  • 2
    @RameshKannan Does \begin{scope}[canvas is xz plane at y=3] \draw[fill=white,fill opacity=0.8] (-2,-2) rectangle (2,2); \draw[thick] (0,0) circle[radius=1.5cm] (-0.8,-0.3) arc[start angle=-120,end angle=-60,radius={0.8/sin(30)}]; \fill (-0.6,0.5) circle[radius=0.1] (0.6,0.5) circle[radius=0.1]; \end{scope} go in the right direction? –  May 15 '20 at 21:02
  • @ Schrödinger's cat, yes the image gets moved, thank you very much. – rakatex May 15 '20 at 21:08
  • 2
    @RameshKannan Maybe \begin{scope}[xscale=-1,canvas is xz plane at y=-6,yshift=-\cubez*0.2cm] \draw[fill=white,fill opacity=0.8] (-2,-2) rectangle (2,2); \draw[thick] (0,0) circle[radius=1.5cm] (-0.8,-0.3) arc[start angle=-120,end angle=-60,radius={0.8/sin(30)}]; \fill (-0.6,0.5) circle[radius=0.1] (0.6,0.5) circle[radius=0.1]; \end{scope}? –  May 15 '20 at 21:14