我做了什么来生成第一个图形:
\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);
但是这些代码效果不太好,没有显示交叉关系。 如何解决这个问题?
\结束{tikzpicture}
我尝试了 PGFplots 包,使用以下代码:
\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}
画平面虽然比较容易,但是表达相交关系的能力还不够。
答案1
一种方法是将平面分成几部分,然后从后到前绘制它们(或使用图层)。像这样:
\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}
答案2
pst-solide3d
我粗略地解决了这个问题,使用提供名为的函数的包fusion
可以解决交叉问题,但仍然留有一些奇怪的错误。
\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}
在我的代码中,如果我删除这些行,编译器将返回一个错误Error: /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]