4

I've a 3D form like below and I want to project that marker in every surface of that form including the one on the top but not the ones behind.. Anyway, I want just to know the way how projection works and if its possible

enter image description here

\documentclass{article}
\usepackage{tikz}
\begin{document}
\pagestyle{empty}

% The following code is generated by Sketch. I have edited it a bit
% to make it easier to read.
\begin{tikzpicture}[join=round]
    \tikzstyle{conefill} = [fill=blue!20,fill opacity=0.8]
    \tikzstyle{ann} = [fill=white,font=\footnotesize,inner sep=1pt]
    \tikzstyle{ghostfill} = [fill=white]
         \tikzstyle{ghostdraw} = [draw=black!50]

    % Second version of the cone
    \begin{scope}[xshift=3.5cm]
    \filldraw[ghostdraw,ghostfill](-.775,1.922)--(-1.162,.283)--(-.274,.5)
                                   --(-.183,2.067)--cycle;
    \filldraw[ghostdraw,ghostfill](-.183,2.067)--(-.274,.5)--(.775,.424) 
                                   --(.516,2.016)--cycle;
    \filldraw[ghostdraw,ghostfill](.516,2.016)--(.775,.424)--(1.369,.1)
                                   --(.913,1.8)--cycle;
    \filldraw[ghostdraw,ghostfill](-.913,1.667)--(-1.369,-.1)--(-1.162,.283)
                                   --(-.775,1.922)--cycle;
    \filldraw[ghostdraw,ghostfill](.913,1.8)--(1.369,.1)--(1.162,-.283)
                                   --(.775,1.545)--cycle;
    \filldraw[ghostdraw,ghostfill](-.516,1.45)--(-.775,-.424)--(-1.369,-.1)
                                   --(-.913,1.667)--cycle;
    \filldraw[ghostdraw,ghostfill](.775,1.545)--(1.162,-.283)--(.274,-.5)
                                   --(.183,1.4)--cycle;
    \filldraw[fill=red,fill opacity=0.5](-.516,1.45)--(-.775,-.424)--(.274,-.5)
                                         --(.183,1.4)--cycle;

    \fill(-.775,-.424) circle (2pt);
    \fill(.274,-.5) circle (2pt);
    \fill(-.516,1.45) circle (2pt);
    \fill(.183,1.4) circle (2pt);
    \path[font=\footnotesize]
            (.913,1.8) node[right] {$i\hbox{$=$}0$}
            (1.369,.1) node[right] {$i\hbox{$=$}1$};
    \path[font=\footnotesize]
            (-.645,.513) node[left] {$j$}
            (.228,.45) node[right] {$j\hbox{$+$}1$};
    \fill[black,font=\footnotesize]
                    (-.516,1.45) node [above] {$P_{00}$}
                    (-.775,-.424) node [below] {$P_{10}$}
                    (.183,1.4) node [above] {$P_{01}$}
                    (.274,-.5) node [below] {$P_{11}$};

    \node[anchor=south west,inner sep=0] at (0,0) {\includegraphics[scale=0.1]{download.png}};
    \end{scope}

\end{tikzpicture}


\end{document}
ROS_Latex
  • 207
  • Better use something other than TikZ for this i.e. something which knows about 3D. In TikZ, you have to fake the 3D in 2D, so every case is going to require setting up the calculations. tikz-3dplot can help with the coordinate system, but projections are something else again. – cfr Aug 21 '17 at 12:55
  • @cfr I think so.. I didn't find any good solution for that – ROS_Latex Aug 21 '17 at 20:30
  • Even tikz3d doesn't do perspective. But a good graphics editor can create them. See https://tex.stackexchange.com/questions/312238/how-to-create-a-tikz-picture-with-a-non-infinite-distance-viewpoint/312959?s=1|0.4711#312959 – John Kormylo Aug 21 '17 at 21:39

1 Answers1

6

More proof of concept than anything else, but basic idea is to draw the shape over a unit square with the vectors set to 1pt (rather than import it) which can be stretched over the required quadrilateral using a non-linear transform.

Setting up the coordinates is tricky (a lot of trial an error).

\documentclass[tikz,border=5]{standalone}
\usepgfmodule{nonlineartransformations}
\makeatletter
\def\stretchovertransform{%
  \pgfgetlastxy\x\y
  \pgfpointlineattime{\y}
    {\pgfpointlineattime{\x}{\southwest}{\southeast}}%
    {\pgfpointlineattime{\x}{\northwest}{\northeast}}%
}
\tikzset{%
  stretch over/.code args={(#1)#2(#3)#4(#5)#6(#7)}{
    \pgfextract@process\southwest{\tikz@scan@one@point\relax(#1)}%
    \pgfextract@process\northwest{\tikz@scan@one@point\relax(#3)}%
    \pgfextract@process\northeast{\tikz@scan@one@point\relax(#5)}%
    \pgfextract@process\southeast{\tikz@scan@one@point\relax(#7)}%
    \tikzset{reset cm, x=1pt, y=1pt}%
    \pgftransformnonlinear{\stretchovertransform}
  }
}
\tikzstyle{conefill} = [fill=blue!20,fill opacity=0.8]
\tikzstyle{ann} = [fill=white,font=\footnotesize,inner sep=1pt]
\tikzstyle{ghostfill} = [fill=white]
\tikzstyle{ghostdraw} = [draw=black!50]
\begin{document}
\begin{tikzpicture}[line join=round, line cap=round]
\filldraw[ghostdraw, ghostfill](-.775,1.922)--(-1.162,.283)--(-.274,.5)
                               --(-.183,2.067)--cycle;
\filldraw[ghostdraw, ghostfill](-.183,2.067)--(-.274,.5)--(.775,.424) 
                               --(.516,2.016)--cycle;
\filldraw[ghostdraw, ghostfill](.516,2.016)--(.775,.424)--(1.369,.1)
                               --(.913,1.8)--cycle;
\filldraw[ghostdraw, ghostfill](-.913,1.667)--(-1.369,-.1)--(-1.162,.283)
                               --(-.775,1.922)--cycle;
\filldraw[ghostdraw, ghostfill](.913,1.8)--(1.369,.1)--(1.162,-.283)
                               --(.775,1.545)--cycle;
\filldraw[ghostdraw, ghostfill]
  (-.516,1.45) coordinate (r01)  --
  (-.775,-.424) coordinate (r11) --
  (-1.369,-.1) coordinate (r10)  --
  (-.913,1.667) coordinate (r00) -- cycle;
\filldraw[ghostdraw, ghostfill]
  (.775,1.545) coordinate (q01) --
  (1.162,-.283) coordinate (q11) --
  (.274,-.5) coordinate (q10) --
  (.183,1.4) coordinate (q00) -- cycle;
\filldraw[fill=red,fill opacity=0.5]
  (-.516,1.45) coordinate (p00) -- 
  (-.775,-.424) coordinate (p10) --
  (.274,-.5) coordinate (p11) --
  (.183,1.4) coordinate (p01) --cycle;

\foreach \i in {p,q,r}{
  \begin{scope}[stretch over={(\i10) (\i00) (\i01) (\i11)}, shift={(0.5,0.5)}, fill=gray, opacity=.875, scale=0.75]                             
  \fill [even odd rule] 
    (-.5,-.5) rectangle ++(1, 1)  (0,0) 
    circle [radius=0.375]
    (90:.375) -- (210:.375) -- (330:.375)
    (90:.25) -- (210:.25) -- (330:.25); 
  \fill (-.1,-.025) rectangle (.1,.025) 
    [rotate=90](-.1,-.025) rectangle (.1,.025) ;
  \fill [white, shift=(45:.5), scale=0.75] (-.1,-.025) rectangle (.1,.025) 
    [rotate=90](-.1,-.025) rectangle (.1,.025) ;
  \fill [white, shift=(225:.5), scale=0.75] (-.1,-.025) rectangle (.1,.025) 
    [rotate=90](-.1,-.025) rectangle (.1,.025);
  \fill [white, shift=(135:.5), rotate=45] (90:.1) -- (210:.1) -- (330:.1);
  \fill [white, shift=(315:.5), rotate=-135] (90:.1) -- (210:.1) -- (330:.1);
  \end{scope}
}                
\end{tikzpicture}
\end{document}

enter image description here

Mark Wibrow
  • 70,437