我想要绘制的是如下图两个圆柱的相交曲线,但是画出来的却是一条直线,为了简单起见,只贴出绘制曲线的基本代码。
\documentclass{border=10pt}[standalone]
\usepackage{tikz}
\begin{document}
\tikzset{%
math3d/.style={%%
x={(-0.353cm,-0.353cm)},
z={(0cm,1cm)},
y={(1cm,0cm)},
}%%
}%
\begin{tikzpicture}[math3d]
\draw node[left] at (0,0,0) {$O$} coordinate (O);
\draw[->](0,0,0)--(4,0,0);
\draw node[below left] at (4,0,0) {$X$};
\draw[->](0,0,0)--(0,5,0);
\draw node[below right] at (0,5,0) {$Y$};
\draw[->](0,0,0)--(0,0,5);
\draw node[below right] at (0,0,5) {$Z$};
% curve as intersection of two cylinders
\draw[variable=\t,samples=30,domain=0:0.5*pi,smooth]
plot ({2*cos(deg(\t))}, {2*sin(deg(\t))},{2*sin(deg(\t))}); %
\end{tikzpicture}
\end{document}
答案1
你选择了一个不合适的投影,曲线看起来像一条线。曲线由以下公式给出
\draw[variable=\t,samples=30,domain=0:0.5*pi,smooth]
plot ({2*cos(deg(\t))}, {2*sin(deg(\t))},{2*sin(deg(\t))});
因此它的y
和z
分量相等。但是,您选择的x
是,使得x
与成比例y+z
,这样您就得到了一条线。为了安装另一个投影,您可以加载库perspective
。以下动画显示,对于某些视角,曲线的投影可能看起来像一条线。
\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{perspective}
\begin{document}
\foreach \X in {100,105,...,130,125,120,...,105}
{\begin{tikzpicture}
\path[use as bounding box] (-3,-3) rectangle (6,6);
\begin{scope}[3d view={\X }{20+15*sin((\X-100)*6)}]
\draw node[left] at (0,0,0) {$O$} coordinate (O);
\draw[->](0,0,0)--(4,0,0);
\draw node[below left] at (4,0,0) {$X$};
\draw[->](0,0,0)--(0,5,0);
\draw node[below right] at (0,5,0) {$Y$};
\draw[->](0,0,0)--(0,0,5);
\draw node[below right] at (0,0,5) {$Z$};
% curve as intersection of two cylinders
\draw[dashed] (2,0,0) -- (2,0,4) -- (0,0,4) -- (0,2,4)
-- (0,2,2) -- (0,4,2) -- (0,4,0) -- (2,4,0) -- cycle
plot[variable=\t,samples=30,domain=0:0.5*pi,smooth]
({2*sin(deg(\t))},4,{2*cos(deg(\t))});
\draw
plot[variable=\t,samples=30,domain=0:0.5*pi,smooth]
({2*cos(deg(\t))}, {2*sin(deg(\t))},{2*sin(deg(\t))});
\draw plot[variable=\t,samples=30,domain=0:0.5*pi,smooth]
({2*cos(deg(\t))}, 0,{2*sin(deg(\t))}) --
(0,2,2) -- (0,2,0)
plot[variable=\t,samples=30,domain=0.5*pi:0,smooth]
({2*cos(deg(\t))},{2*sin(deg(\t))},0);
\end{scope}
\end{tikzpicture}}
\end{document}