我已经成功使用 绘制了一条 3D 参数曲线pgfplots
,但我想在我的图中添加支撑线以增加深度,即从图到xy
-平面的垂直线。有人知道如何做到这一点,而无需手动添加曲线上各个点的线条吗?
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
height=15cm,
width=15cm,
clip=false,
axis lines = middle,
ticks=none,
xmin=-2,xmax=6,
ymin=-6,ymax=6,
zmin=-1,zmax=6,
]
\addplot3 [only marks,mark=*] coordinates {(5,5,1) (1,5,2)};
\addplot3 [only marks,mark=x,mark size=3pt] coordinates {(-1,-5,5) (5,-2,2)};
\node[anchor=north] at (axis cs:5,5,1) {$(5,5,1)$};
\node[anchor=south] at (axis cs:-1,-5,5) {$(-1,-5,5)$};
\node[anchor=west] at (axis cs:5,-2,2) {$(5,-2,2)$};
\node[anchor=south] at (axis cs:1,5,2) {$(1,5,2)$};
\draw[dashed] (axis cs:5,5,1) -- (axis cs:-1,-5,5) -- (axis cs:5,-2,2) -- (axis cs:1,5,2);
\addplot3 [y domain=0:0,
domain=0:1,
samples=50,
variable=\t]({-22*t^3+36*t^2-18*t+5},{-9*t^3+39*t^2-30*t+5},{10*t^3-21*t^2+12*t+1});
\end{axis}
\end{tikzpicture}
\end{document}
答案1
您可以使用该功能添加“虚拟”图来实现此目的ycomb
。有关更多详细信息,请查看代码中的注释。
% used PGFPlots v1.14
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
height=15cm,
width=15cm,
clip=false,
axis lines=middle,
ticks=none,
xmin=-2,xmax=6,
ymin=-6,ymax=6,
zmin=-1,zmax=6,
]
% before plotting the "real" plot add the `ycomb' plot with a
% reduced number of sample ploints
\addplot3 [
draw=black!25,
y domain=0:0,
domain=0:1,
samples=11,
variable=\t,
ycomb,
] (
{-22*t^3+36*t^2-18*t+5},
{-9*t^3+39*t^2-30*t+5},
{10*t^3-21*t^2+12*t+1}
);
% now plot the real line
\addplot3 [
y domain=0:0,
domain=0:1,
samples=50,
variable=\t,
] (
{-22*t^3+36*t^2-18*t+5},
{-9*t^3+39*t^2-30*t+5},
{10*t^3-21*t^2+12*t+1}
);
\addplot3 [only marks,mark=*] coordinates {(5,5,1) (1,5,2)};
\addplot3 [only marks,mark=x,mark size=3pt] coordinates {(-1,-5,5) (5,-2,2)};
\node [anchor=north] at (axis cs:5,5,1) {$(5,5,1)$};
\node [anchor=south] at (axis cs:-1,-5,5) {$(-1,-5,5)$};
\node [anchor=west] at (axis cs:5,-2,2) {$(5,-2,2)$};
\node [anchor=south] at (axis cs:1,5,2) {$(1,5,2)$};
\draw [dashed] (axis cs:5,5,1) -- (axis cs:-1,-5,5)
-- (axis cs:5,-2,2) -- (axis cs:1,5,2);
\end{axis}
\end{tikzpicture}
\end{document}