我一直尝试使用 pgfplot 绘制这个表面,但我无法使它看起来像我尝试为其制作代码的图片。
\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[view = {70}{-40},
xmax = 4,
xmin = -4,
ymax = 4,
ymin = -4,
restrict z to domain = -2:5]
\addplot3 [
domain=-3:3,
domain y = -3:3,
surf] {x^2 + y^2};
\end{axis}
\end{tikzpicture}
\end{document}
我也确实想在我的表面之外绘制一些其他表面,但我不知道该怎么做。(见图片)
我真心希望您能给我指明正确的方向。
答案1
surf
对于完全平坦的区域使用绘图是没有意义的- 只需\fill
像这样使用:
\documentclass[border=1 cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
view={45}{20},
xmin=-4, xmax=4,
ymin=-4, ymax=4,
zmin=-2, zmax=5,
axis lines=middle,
axis on top,
]
\fill[red!80!black] plot[domain=-sqrt(2.5):sqrt(2.5),samples=100] (\x,\x,{2*(\x)^2}) --cycle;
\fill[red!80!pink] (0,0,5) circle[radius=sqrt(5)];
\end{axis}
\end{tikzpicture}
\end{document}
如果您希望用网格或其他东西对其进行阴影处理,则可以使用surf
如下图所示的绘图:
\documentclass[border=1 cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
colormap/hot2,
view={45}{20},
xmin=-4, xmax=4,
ymin=-4, ymax=4,
zmin=-2, zmax=5,
restrict z to domain=-2:6,
axis lines=middle,
axis on top,
]
\addplot3[
surf,
samples=51,
] {x^2 + y^2};
\fill[white] (0,0,5) +(-2cm,0cm) rectangle +(2cm,1cm);
\draw[fill=red!80!pink] (0,0,5) circle[radius=sqrt(5)];
\end{axis}
\end{tikzpicture}
\end{document}
答案2
第一个图形带有渐近线。其他图形可以用类似的方式绘制。
import graph3;
currentprojection=orthographic(2,1.5,.5,zoom=.95);
unitsize(1cm);
//currentprojection=obliqueX(40);
size(8cm);
real a=4.5; // below z=a
triple f(pair M) {
real x = sqrt(a)*(M.x)*cos(M.y);
real y = sqrt(a)*(M.x)*sin(M.y);
return (x,y,x^2+y^2);
}
real rmax = 1, rmin =0;
real phimax =2*pi, phimin =0;
surface s=surface(f, (rmin,phimin), (rmax,phimax), Spline);
//draw(s, surfacepen=pink,meshpen=brown+thick());
draw(s,surfacepen=yellow+opacity(.7));
real b=2.5;
real x(real t) {return sqrt(b)*cos(t);}
real y(real t) {return sqrt(b)*sin(t);}
real z(real t) {return b;}
path3 g=graph(x,y,z,phimin,phimax,operator..);
draw(g,red+1pt);
draw(shift(-3,-3,b)*scale(6,6,0)*unitplane,blue+opacity(.5));
draw(Label("$x$",EndPoint),-5*X--5*X,Arrow3());
draw(Label("$y$",EndPoint),-5*Y--5*Y,Arrow3());
draw(Label("$z$",EndPoint),-Z--6*Z,Arrow3());
第二张图:我们可以玩一下opacity
数值,去掉红框。我选择的是抛物柱面z=1+2y^2
。
// http://asymptote.ualberta.ca/
unitsize(1cm);
size(8cm);
import graph3;
currentprojection=orthographic(2,1.4,.6,zoom=.95);
//currentprojection=obliqueX(40);
// the yellow paraboloid z=f(x,y)= x^2+y^2
real a=2.25; // below z=a^2
// to take domain is a disk (instead of a rectangle)
triple f(pair M) {
real x = a*(M.x)*cos(M.y);
real y = a*(M.x)*sin(M.y);
return (x,y,x^2+y^2);
}
real rmax=1, rmin=0;
real phimax=2*pi, phimin=0;
surface sf=surface(f, (rmin,phimin), (rmax,phimax), Spline);
//draw(sf, surfacepen=pink,meshpen=brown+thick());
draw(sf,surfacepen=yellow+opacity(1));
triple h(pair M) {
if (1+2M.y^2>a^2) return (M.x,M.y,a^2);
else return (M.x,M.y,1+2M.y^2);
}
real xmax=4, xmin=-4;
real ymax=1.5, ymin=-1.5;
surface sh=surface(h, (xmin,ymin), (xmax,ymax), Spline);
//draw(sh, surfacepen=pink,meshpen=brown+thick());
draw(sh,surfacepen=blue+opacity(.8));
triple A=(xmin,ymin,0), B=(xmax,ymax,a^2);
draw(box(A,B),red+opacity(.5));
// the red circle x^2+y^2=b^2 is the intersection of
// the blue plane z=b^2 and the paraboloid
real b=1.6;
real x(real t) {return b*cos(t);}
real y(real t) {return b*sin(t);}
real z(real t) {return b^2;}
path3 g=graph(x,y,z,phimin,phimax,operator..);
//draw(g,red+1pt);
//draw(shift(-3,-3,b^2)*scale(6,6,0)*unitplane,blue+opacity(1));
draw(Label("$x$",EndPoint),-5*X--5*X,Arrow3());
draw(Label("$y$",EndPoint),-5*Y--5*Y,Arrow3());
draw(Label("$z$",EndPoint),-Z--7*Z,Arrow3());
答案3
我提供 Ti钾Z 解决方案。我认为对于这个图形,以 2d 形式绘制更容易,所以我这样做了。
我不会发布数学公式,因为如果没有 MathJax 或类似的东西,这会很乏味。但这里的关键是找到信封通过水平面切割抛物面获得的椭圆族(三维圆)。
以这种方式绘制所有计算都是精确的(就 Ti钾Z 走)并且所有曲线都是 Ti钾Z path
s,我不使用plot
(参见更新 1以下)。
代码:
\documentclass[tikz,border=2mm]{standalone}
\tikzset
{%
axes/.style={thick,-latex},
paraboloid front/.style={right color=red!80,left color=white,fill opacity=0.6},
paraboloid back/.style={left color=red!80,fill opacity=0.6},
plane/.style={blue,fill=blue!50,fill opacity=0.8},
}
\begin{document}
\begin{tikzpicture}[line cap=round,line join=round]
% axes x,y
\draw[axes] (30:4) -- (210:4) node [left] {$x$};
\draw[axes] (150:4) -- (330:4) node [right] {$y$};
\draw[thick] (0,0) -- (0,2.25);
% paraboloid, bottom, back
\draw[paraboloid back] ({0.25*sqrt(51)},2) parabola bend (0,-0.125) ({-0.25*sqrt(51)},2)
arc ({180+atan(1/sqrt(17))}:{-atan(1/sqrt(17))}:{0.75*sqrt(6)} and {0.75*sqrt(2)});
% paraboloid, bottom, front
\draw[paraboloid front] ({0.25*sqrt(51)},2) parabola bend (0,-0.125) ({-0.25*sqrt(51)},2)
arc ({180+atan(1/sqrt(17))}:{360-atan(1/sqrt(17))}:{0.75*sqrt(6)} and {0.75*sqrt(2)});
% horizontal plane
\draw[plane] (210:3) ++ (0,2.25) ++ (330:3.5) --++ (30:6) --++ (150:7) --++ (210:6) -- cycle;
% paraboloid, top, back
\draw[paraboloid back] ({0.25*sqrt(93)},3.75) parabola bend (0,-0.125) ({0.25*sqrt(51)},2)
arc ({-atan(1/sqrt(17))}:{180+atan(1/sqrt(17))}:{0.75*sqrt(6)} and {0.75*sqrt(2)})
parabola bend (0,-0.125) ({-0.25*sqrt(93)},3.75)
arc ({180+atan(1/sqrt(31))}:{-atan(1/sqrt(31))}:{sqrt(6)} and {sqrt(2)});
% axis z
\draw[axes] (0,2.25) -- (0,6) node [above] {$z$};
% paraboloid, top, front
\draw[paraboloid front] ({0.25*sqrt(93)},3.75) parabola bend (0,-0.125) ({0.25*sqrt(51)},2)
arc ({-atan(1/sqrt(17))}:{-180+atan(1/sqrt(17))}:{0.75*sqrt(6)} and {0.75*sqrt(2)})
parabola bend (0,-0.125) ({-0.25*sqrt(93)},3.75)
arc ({180+atan(1/sqrt(31))}:{360-atan(1/sqrt(31))}:{sqrt(6)} and {sqrt(2)});
\end{tikzpicture}
\end{document}
更新 1:我一开始没看出来,但上面的代码无法正确显示可见性。这是因为parabola bend
尽管指定的最后一个点位于该顶点之前,但路径仍将抛物线绘制到顶点。所以我认为parabola
这毕竟不是正确的做法。我可以做一个剪辑,但找到合适的路径并不容易。也许spath3
库可以解决问题,我将来会研究一下(参见更新 2以下)。
同时,与 s 相同的绘图plot
:
\documentclass[tikz,border=2mm]{standalone}
\tikzset
{%
axes/.style={thick,-latex},
paraboloid front/.style={right color=red!80,left color=white,fill opacity=0.6},
paraboloid back/.style={left color=red!80,fill opacity=0.6},
plane/.style={blue,fill=blue!50,fill opacity=0.8},
}
\newcommand{\myparabola}[2]{-- plot [domain={#1}:{#2},samples=40] (\x,2/3*\x*\x-0.125)}
\begin{document}
\begin{tikzpicture}[line cap=round,line join=round]
% dimensions
\pgfmathsetmacro\angTC{atan(1/sqrt(31))} % angles, top circle
\pgfmathsetmacro\angBC{atan(1/sqrt(17))} % angles, bottom circle
\pgfmathsetmacro\TTx {0.25*sqrt(93)} % tangent point x, top circle
\pgfmathsetmacro\TBx {0.25*sqrt(51)} % tangent point x, bottom circle
% axes x,y
\draw[axes] (30:4) -- (210:4) node [left] {$x$};
\draw[axes] (150:4) -- (330:4) node [right] {$y$};
\draw[thick] (0,0) -- (0,2.25);
% paraboloid, bottom, back
\draw[paraboloid back] (-\TBx,2)
arc (180+\angBC:-\angBC:{0.75*sqrt(6)} and {0.75*sqrt(2)}) \myparabola{\TBx}{-\TBx};
% paraboloid, bottom, front
\draw[paraboloid front] (-\TBx,2)
arc (180+\angBC:360-\angBC:{0.75*sqrt(6)} and {0.75*sqrt(2)}) \myparabola{\TBx}{-\TBx};
% horizontal plane
\draw[plane] (210:3) ++ (0,2.25) ++ (330:3.5) --++ (30:6) --++ (150:7) --++ (210:6) -- cycle;
% paraboloid, top, back
\draw[paraboloid back] (\TBx,2)
arc (-\angBC:180+\angBC:{0.75*sqrt(6)} and {0.75*sqrt(2)}) \myparabola{-\TBx}{-\TTx}
arc (180+\angTC:-\angTC:{sqrt(6)} and {sqrt(2)}) \myparabola{\TTx}{\TBx};
% axis z
\draw[axes] (0,2.25) -- (0,6) node [above] {$z$};
% paraboloid, top, front
\draw[paraboloid front] (\TBx,2)
arc (-\angBC:-180+\angBC:{0.75*sqrt(6)} and {0.75*sqrt(2)}) \myparabola{-\TBx}{-\TTx}
arc (180+\angTC:360-\angBC:{sqrt(6)} and {sqrt(2)}) \myparabola{\TTx}{\TBx};
\end{tikzpicture}
\end{document}
以及绘图(具有正确的可见性):
更新 2:这是我第一次尝试使用 Andrew Stacey 的spath3
库。我不知道我是否清楚自己在做什么,所以使用它需要您自担风险!!(它需要 TL2021,我不知道其他 LaTeX 发行版是否如此)。
我正在关注 Andrew 的这里回答得很好(第二篇)一步一步。其实关于的评论spath3
都是他的(我改了一两个词)。当然,错误都是我的。
新代码:
\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{intersections,spath3}
\tikzset
{%
axes/.style={thick,-latex},
paraboloid front/.style={right color=red!80,left color=white,fill opacity=0.6},
paraboloid back/.style={left color=red!80,fill opacity=0.6},
plane/.style={blue,fill=blue!50,fill opacity=0.8},
}
\begin{document}
\begin{tikzpicture}[line cap=round,line join=round]
% creating the paths: parabola, two ellipses and two lines (for cutting)
\path[spath/save=P] ({-0.25*sqrt(93)},3.75) parabola bend (0,-0.125) ({0.25*sqrt(93)},3.75);
\path[spath/save=EB] (0,2.25) ellipse ({0.75*sqrt(6)} and {0.75*sqrt(2)}); % ellipse, bottom
\path[spath/save=ET] (0,4) ellipse ({sqrt(6)} and {sqrt(2)}); % ellipse, top
\path[spath/save=LB] (-3,2) -- (3,2); % line, bottom
\path[spath/save=LT] (-3,3.75) -- (3,3.75); % line, top
% spath3 operations
\tikzset
{% Ellipses have an "empty" component at the start which
% moves from the centre to the rim; it can be irritating
% when trying to count components later so this removes
% any empty components
spath/remove empty components={EB},
spath/remove empty components={ET},
% Now split each path where it intersects with the lines
spath/split at intersections={P}{LB},
spath/split at intersections={EB}{LB},
spath/split at intersections={ET}{LT},
% Each path is now a collection of components; to work
% with them individually we split them into a list of
% separate paths which is stored in a macro
spath/get components of={P}\Pcpts,
spath/get components of={EB}\Bcpts,
spath/get components of={ET}\Tcpts,
}
% axes x,y
\draw[axes] (30:4) -- (210:4) node [left] {$x$};
\draw[axes] (150:4) -- (330:4) node [right] {$y$};
\draw[thick] (0,0) -- (0,2.25);
% paraboloid, bottom, back
\draw[paraboloid back,
spath/use=\getComponentOf\Pcpts{2},
spath/use={\getComponentOf\Bcpts{2},weld},
];
% paraboloid, bottom, front
\draw[paraboloid front,
spath/use=\getComponentOf\Pcpts{2},
spath/use={\getComponentOf\Bcpts{1},reverse,weld}
];
% horizontal plane
\draw[plane] (210:3) ++ (0,2.25) ++ (330:3.5) --++ (30:6) --++ (150:7) --++ (210:6) -- cycle;
% paraboloid, top, back
\draw[paraboloid back,
spath/use=\getComponentOf\Pcpts{1},
spath/use={\getComponentOf\Bcpts{2},reverse,weld},
spath/use={\getComponentOf\Pcpts{3},weld},
spath/use={\getComponentOf\Tcpts{2},weld}
];
% axis z
\draw[axes] (0,2.25) -- (0,6) node [above] {$z$};
% paraboloid, top, front
\draw[paraboloid front,
spath/use=\getComponentOf\Pcpts{1},
spath/use={\getComponentOf\Bcpts{1},weld},
spath/use={\getComponentOf\Pcpts{3},weld},
spath/use={\getComponentOf\Tcpts{1},reverse,weld}
];
\end{tikzpicture}
\end{document}
输出与上面相同。