2

enter image description here

what I did to generate the first figure:

  \begin{tikzpicture}
    [3d view={60}{30}]
% bottom plane
\draw[plane,fill=blue!50] 
(-1,-1,0) -- (1,-1,0) -- (1,1,0) -- (-1,1,0) -- cycle;
\draw[plane,fill=green!50] 
(0,-1,-1) -- (0,1,-1) -- (0,1,1) -- (0,-1,1) -- cycle;
\draw[plane,fill=red!50] 
(-1,0,-1) -- (1,0,-1) -- (1,0,1) -- (-1,0,1) -- cycle;
\draw[line,thin] (-1,0,0)--(1,0,0) (0,-1,0)--(0,1,0) (0,0,1)--(0,0,-1);

but these code don't work well, it doesn't show the intersection relationship. enter image description here how to solve the problem ?

\end{tikzpicture}

and I tried the package PGFplots, using these code:

    \begin{tikzpicture}
    \begin{axis}[
      axis lines=center,
      plot box ratio={1}{1}{1},
      view={60}{45},
      samples=2,
      domain=-1:1,
      ]
    \addplot3[surf,opacity=0.5]{x+y};                
    \addplot3[surf,opacity=0.5]{y};   
    \addplot3[surf,opacity=0.5]{x};                 
    \end{axis}
    \end{tikzpicture}

it is easy to draw plane but still lack of the ablity to express intersection relationship .

  • 1
    All of these are already done somewhere. The arguably most complicated one is the third one, it can be found here. –  Sep 01 '19 at 01:13
  • 1
    In either case you need to split the planes in intersection components and draw them in the right order. This may not be necessary if you use the patchplots library that comes with pgfplots or switch to asymptote. (pstricks also has some automatic 3d ordering but the output is arguably less appealing than what you get with the other options.) –  Sep 01 '19 at 01:54
  • 3
    Last comment: you only posted code fragments. Does that mean you will be accepting an answer that only contains fragments, too? –  Sep 01 '19 at 02:00

2 Answers2

2

One way to do this could be by separating the planes into several pieces and drawing them from back to front (or using layers). Like this:

\documentclass[border=2mm]{standalone}
\usepackage    {tikz}
\usetikzlibrary{3d}

\begin{document} \begin{tikzpicture}[line cap=round,line join=round,x={(-0.8562cm,-0.3116cm)},y={(0.5166cm,-0.5166cm)},z={(0cm,0.7975cm)}] \def\op{1} \draw[fill=red!50, fill opacity=\op] ( 0,-1,-1) -- ( 0,0,-1) -- (0,0,0) -- ( 0,-1,0) -- cycle; % It doesn't show \draw[fill=green!50,fill opacity=\op] (-1, 0,-1) -- ( 1,0,-1) -- (1,0,0) -- (-1, 0,0) -- cycle; \draw[fill=red!50, fill opacity=\op] ( 0, 1,-1) -- ( 0,0,-1) -- (0,0,0) -- ( 0, 1,0) -- cycle; \draw[fill=blue!50, fill opacity=\op] (-1,-1, 0) -- (-1,1, 0) -- (1,1,0) -- ( 1,-1,0) -- cycle; \draw[fill=red!50, fill opacity=\op] ( 0,-1, 0) -- ( 0,0, 0) -- (0,0,1) -- ( 0,-1,1) -- cycle; \draw[fill=green!50,fill opacity=\op] (-1, 0, 0) -- ( 1,0, 0) -- (1,0,1) -- (-1, 0,1) -- cycle;
\draw[fill=red!50, fill opacity=\op] ( 0, 1, 0) -- ( 0,0, 0) -- (0,0,1) -- ( 0, 1,1) -- cycle;
\end{tikzpicture}

\begin{tikzpicture}[line cap=round,line join=round,x={(-0.8562cm,-0.3116cm)},y={(0.5166cm,-0.5166cm)},z={(0cm,0.7975cm)}] \def\op{0.8} \draw[fill=red!50, fill opacity=\op] ( 0,-1,-1) -- ( 0,0,-1) -- (0,0,0) -- ( 0,-1,0) -- cycle; \draw[fill=green!50,fill opacity=\op] (-1, 0,-1) -- ( 1,0,-1) -- (1,0,0) -- (-1, 0,0) -- cycle; \draw[fill=red!50, fill opacity=\op] ( 0, 1,-1) -- ( 0,0,-1) -- (0,0,0) -- ( 0, 1,0) -- cycle; \draw[fill=blue!50, fill opacity=\op] (-1,-1, 0) -- (-1,1, 0) -- (1,1,0) -- ( 1,-1,0) -- cycle; \draw[fill=red!50, fill opacity=\op] ( 0,-1, 0) -- ( 0,0, 0) -- (0,0,1) -- ( 0,-1,1) -- cycle; \draw[fill=green!50,fill opacity=\op] (-1, 0, 0) -- ( 1,0, 0) -- (1,0,1) -- (-1, 0,1) -- cycle;
\draw[fill=red!50, fill opacity=\op] ( 0, 1, 0) -- ( 0,0, 0) -- (0,0,1) -- ( 0, 1,1) -- cycle;
\end{tikzpicture} \end{document}

The drawing has two figures, with different opacity values: enter image description here

Juan Castaño
  • 28,426
1

I solved this problem roughly , using the package pst-solide3d which offer a function named fusion could sovle the intersection problem ,but still remaining some weird bugs.


\documentclass{article}
\usepackage[dvipsnames]{pstricks}
\usepackage{pst-solides3d}
\pagestyle{empty}

\begin{document}

\newcommand\hjpunit{0.3cm}
\newcommand\hjpcoorsize{(-5,-5)(5,5)}
\newcommand\hjpplancolor{gray!70}
\newcommand\hjpplinecolor{white}
\newcommand\hjpplinewidth{0.1pt}
\newcommand\hjpngrid{8 8}
\psset{unit=\hjpunit}
.
    \begin{pspicture}(-5,-5)(5,5)%这个没法宏替换,会出问题
        \psset{Decran=10,viewpoint=40 55 40 rtp2xyz, lightsrc=viewpoint}
      \defFunction[algebraic]{Func}(x,y){}{}{(x^0.3)*(y^0.7)}
      \psSolid[object=surface,base=0 18 0 18,function=Func,ngrid=\hjpngrid,
               name=FUNC,action=none]
      % 只要去掉前面的注释,就可以完美运行,添加就运行不了,是一个奇怪的问题
      \psSolid[object=plan,definition=equation,
         args={[1 0 0 0]},% 0.5x+0.7y-10=0
         base=-15 15 -10 10 ,ngrid=\hjpngrid,fillcolor=\hjpplancolor,
         name=PLANE0,action=none]
      \psSolid[object=plan,definition=equation,
         args={[0 1 0 0]},% 0.5x+0.7y-10=0
         base= -10 10 -15 15,ngrid=\hjpngrid,fillcolor=\hjpplancolor,
         name=PLANE1,action=none]
      \psSolid[object=plan,definition=equation,
         args={[0 0 1 0]},% 0.5x+0.7y-10=0
         base=-10 10 -10 10,ngrid=\hjpngrid,fillcolor=\hjpplancolor,
         name=PLANE2,action=none]
        %\psSolid[object=fusion,base=PLANE_s FUNC ]
        \psSolid[object=fusion,base=PLANE0_s PLANE1_s PLANE2_s,linewidth=\hjpplinewidth,linecolor=\hjpplinecolor,fillcolor=blue!20,
      ]
       %\gridIIID[Zmin=-4,Zmax=16](0,16)(0,16)
      \end{pspicture}
.
    \begin{pspicture}(-5,-5)(5,5)
        \psset{Decran=10,viewpoint=35 100 35 rtp2xyz, lightsrc=viewpoint}
        \defFunction[algebraic]{Func}(x,y){}{}{(x^0.3)*(y^0.7)}
        \psSolid[object=surface,base=0 18 0 18,function=Func,ngrid=\hjpngrid,
                 name=FUNC,action=none]
        % 只要去掉前面的注释,就可以完美运行,添加就运行不了,是一个奇怪的问题
        \psSolid[object=plan,definition=equation,
           args={[-1 0 1 -1]},% 0.5x+0.7y-10=0
           base=-15 15 -5 5,ngrid=\hjpngrid,fillcolor=\hjpplancolor,
           name=PLANE0,action=none]
        \psSolid[object=plan,definition=equation,
           args={[1 0 1 -1]},% 0.5x+0.7y-10=0
           base=-15 15 -5 5,ngrid=\hjpngrid,fillcolor=\hjpplancolor,
           name=PLANE1,action=none]
        \psSolid[object=plan,definition=equation,
           args={[0 0 1 -1]},% 0.5x+0.7y-10=0
           base=-15 15 -5 5,ngrid=\hjpngrid,fillcolor=\hjpplancolor,
           name=PLANE2,action=none]
          %\psSolid[object=fusion,base=PLANE_s FUNC ]
          \psSolid[object=fusion,base=PLANE0_s PLANE1_s PLANE2_s,linewidth=\hjpplinewidth,linecolor=\hjpplinecolor,fillcolor=blue!20,
        ]
         %\gridIIID[Zmin=-4,Zmax=16](0,16)(0,16)
        \end{pspicture}
.
    \begin{pspicture}(-5,-5)(5,5)
        \psset{Decran=10,viewpoint=35 120 60 rtp2xyz, lightsrc=viewpoint}
        \defFunction[algebraic]{Func}(x,y){}{}{(x^0.3)*(y^0.7)}
        \psSolid[object=surface,base=0 18 0 18,function=Func,ngrid=\hjpngrid,
                 name=FUNC,action=none]
        % 只要去掉前面的注释,就可以完美运行,添加就运行不了,是一个奇怪的问题
        \psSolid[object=plan,definition=equation,
           args={[-4 0 1 -9]},% 0.5x+0.7y-10=0
           base=-15 15 -5 5,ngrid=\hjpngrid,fillcolor=\hjpplancolor,
           name=PLANE0,action=none](-6,0,0)
        \psSolid[object=plan,definition=equation,
           args={[1.5 0 1 -8]},% 0.5x+0.7y-10=0
           base=-15 15  -5 5,ngrid=\hjpngrid,fillcolor=\hjpplancolor,
           name=PLANE1,action=none](4,0,0)
        \psSolid[object=plan,definition=equation,
           args={[0 0 1 -1]},% 0.5x+0.7y-10=0
           base=-15 15  -5 5,ngrid=\hjpngrid,fillcolor=\hjpplancolor,
           name=PLANE2,action=none]
          %\psSolid[object=fusion,base=PLANE_s FUNC ]
          \psSolid[object=fusion,base=PLANE0_s PLANE1_s PLANE2_s,linewidth=\hjpplinewidth,linecolor=\hjpplinecolor,fillcolor=blue!20,
        ]
         %\gridIIID[Zmin=-4,Zmax=16](0,16)(0,16)
        \end{pspicture}
.
    \begin{pspicture}(-5,-5)(5,5)
        \psset{Decran=10,viewpoint=30 65 30 rtp2xyz, lightsrc=viewpoint}
        \defFunction[algebraic]{Func}(x,y){}{}{(x^0.3)*(y^0.7)}
        \psSolid[object=surface,base=0 18 0 18,function=Func,ngrid=\hjpngrid,
                 name=FUNC,action=none]
        % 只要去掉前面的注释,就可以完美运行,添加就运行不了,是一个奇怪的问题
        \psSolid[object=plan,definition=equation,
           args={[1 0 0 6]},% 0.5x+0.7y-10=0
           base=-10 10 -5 5,ngrid=\hjpngrid,fillcolor=\hjpplancolor,
           name=PLANE0,action=none]
        \psSolid[object=plan,definition=equation,
           args={[1 0 0 -6]},% 0.5x+0.7y-10=0
            base=-10 10 -5 5,ngrid=\hjpngrid,fillcolor=\hjpplancolor,
           name=PLANE1,action=none]
        \psSolid[object=plan,definition=equation,
           args={[0 0 1 0]},% 0.5x+0.7y-10=0
           base=-15 15 -5 5,ngrid=\hjpngrid,fillcolor=\hjpplancolor,
           name=PLANE2,action=none]
          %\psSolid[object=fusion,base=PLANE_s FUNC ]
          \psSolid[object=fusion,base=PLANE0_s PLANE1_s PLANE2_s,linewidth=\hjpplinewidth,linecolor=\hjpplinecolor,fillcolor=blue!20,
        ]
         %\gridIIID[Zmin=-4,Zmax=16](0,16)(0,16)
        \end{pspicture}
\end{document}



enter image description here

in my code , if I delete these lines , compiler will return an error saidError: /undefined in PLANE0_s

        \defFunction[algebraic]{Func}(x,y){}{}{(x^0.3)*(y^0.7)}
        \psSolid[object=surface,base=0 18 0 18,function=Func,ngrid=\hjpngrid,
                 name=FUNC,action=none]