如何绘制两个相交的圆柱体?

如何绘制两个相交的圆柱体?

通过使用 TikZ 包,我想要绘制这个:

在此处输入图片描述

在此处输入图片描述

对于下面的结果,我仍然需要 GeoGebra 的帮助。(对于我来说,在倾斜位置和阴影中绘制弧线很困难。)

\documentclass[border=10pt]{standalone}
\usepackage[x11names,dvipsnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{intersections,calc}

\begin{document}

\begin{tikzpicture}[font=\scriptsize]
\coordinate (A) at (0,0);
\coordinate (B) at (30:5.4);
\coordinate (C) at ($(A)!3cm!-90:(B)$);
\coordinate (D) at ($(B)!3cm!90:(A)$);
\coordinate (E) at (-20:6);
\coordinate (F) at (149:.5);
\coordinate (G) at ($(E)!3cm!-90:(F)$);
\coordinate (H) at ($(F)!3cm!90:(E)$);
\coordinate (K) at ($(A)!.5!(C)$);
\coordinate (L) at ($(B)!.5!(D)$);
\coordinate (M) at ($(E)!.5!(G)$);
\coordinate (N) at ($(F)!.5!(H)$);
\path[name path=g1] (A)--(B);
\path[name path=g2] (C)--(D);
\path[name path=g3] (E)--(F);
\path[name path=g4] (G)--(H);
\path [name intersections={of = g3 and g1, by={P}}];
\path [name intersections={of = g3 and g2, by={Q}}];
\path [name intersections={of = g4 and g1, by={R}}];

\path[preaction={fill=Emerald,nearly transparent}] (A)--(C)--(D)--(B)--cycle;
\path[preaction={fill=Emerald,nearly transparent}] (E)--(F)--(H)--(G)--cycle;
%\draw[] (A)--(B) (C)--(D) (E)--(F) (G)--(H);
\draw[thick,rotate=-150] 
  let 
  \p1=($(A)-(K)$), 
  \n1={veclen(\x1,\y1)}
  in
  (K) circle (1cm and \n1);
\draw[thick,rotate=24.5] 
  let 
  \p1=($(B)-(L)$), 
  \n1={veclen(\x1,\y1)}
  in
  (D) arc (-79:96:1cm and \n1);
\draw[thick,rotate=160] 
  let 
  \p1=($(G)-(M)$),
  \n1={veclen(\x1,\y1)}
  in
  (M) circle (1cm and \n1);
\draw[thick,rotate=-15] 
  let 
  \p1=($(F)-(N)$), 
  \n1={veclen(\x1,\y1)}
  in
  (F) arc (260:82.5:1cm and \n1);
%\foreach \t in {A,B,C,D,E,F,G,H,P,Q,R}
%\draw[fill] (\t) node[below] {\t} circle (1.5pt);
\end{tikzpicture}

\end{document}

在此处输入图片描述

答案1

addplot3这是绘制圆柱体交点的一种方法TikZ/PGFPlots

在此处输入图片描述 在此处输入图片描述

代码为X 气缸

\documentclass[border=3mm]{standalone}

\usepackage{pgfplots}
    \pgfplotsset{compat=1.15}

\begin{document}

\begin{tikzpicture}
  \begin{axis}[%
        axis equal,
        enlargelimits = true,
        samples = 45, samples y = 45,
        axis lines = none, ticks = none,
        cyl/.style = {%
                surf,
                black!30!,
                variable = \u,
                variable y = \v,
                z buffer = sort,
                faceted color=black!70!,
                },
        view/h = 125, view/v = 25
        ]
    \addplot3[%         (-) X-SEMIAXIS
        cyl,
        domain = -3:3,
        y domain = 0:360,
        ] ({min(u,-abs(cos(v)))}, {cos(v)}, {sin(v)});

    \addplot3[%         (+) Y-SEMIAXIS
        cyl,
        domain = 0:360,
        y domain = -3:3,
        ] ({cos(u)}, {max(v,abs(cos(u)))}, {sin(u)});

    \addplot3[%         (-) Y-SEMIAXIS
        cyl,
        domain = 0:360,
        y domain = -3:3,
        ] ({cos(u)}, {min(-abs(cos(u)),v)}, {sin(u)});

    \addplot3[%         (+) X-SEMIAXIS
        cyl,
        domain = -3:3,
        y domain = 0:360,
        ] ({max(u,abs(cos(v)))}, {cos(v)}, {sin(v)});

    \end{axis}
\end{tikzpicture}

\end{document}

这是代码T 型气缸带有尺寸隔间。

\begin{tikzpicture}
  \begin{axis}[%
        axis equal,
        enlargelimits=true,
        samples = 40, samples y = 40,
        axis lines=none, ticks=none,
        cyl/.style = {%
                surf,
                black!30!,
                variable = \u,
                variable y = \v,
                z buffer = sort,
                faceted color=black!70!,
                },
        view/h=135, view/v=35
        ]%

    % COTES
    \tikzstyle{cote} = [%
        blue, fill=white, 
        font=\footnotesize, 
        inner sep=0pt]
    \tikzstyle{clines} = [%
        thin, blue!80!]

    \draw[clines] (3,-2,0) -- (3,0,0);
    \draw[clines] (-3,-2,0) -- (-3,0,0);
    \draw[|<->|, >=latex, thin, blue!80!] (-3,-2,0) -- (3,-2,0);
    \node[cote] at (0,-2,0) {$L_1$};

    % X CYLINDER
    \addplot3[%
        cyl,
        domain = -3:3,
        y domain = 0:360,
        ] ({u}, {cos(v)}, {sin(v)});

    % Y CYLINDER
    \addplot3[%
        cyl,
        domain = 0:360,
        y domain = -3:3,
        ] ({cos(u)}, {max(v,abs(cos(u)))}, {sin(u)});

    \draw[clines] (0,3,0) -- (4.5,3,0);
    \draw[clines] (3,-1,0) -- (4.5,-1,0);
    \draw[|<->|, >=latex, thin, blue!80!] (4.5,-1,0) -- (4.5,3,0);
    \node[cote] at (4.5,1,0) {$L_2$};

    \end{axis}
\end{tikzpicture}

笔记

  • 为了更好地可视化和便于操作,圆柱体的每一半都绘制在不同的图中。感谢@Marmot 对我的问题的回答PGFPlots 中的截头圆柱体,我可以将截头圆柱体的部分分离为一半沿着各自轴的两侧。它们在图中出现的顺序有一个原因:是为了避免在可视化中重叠。
  • 为了简化代码,使它们最终能够通过商品轻松更改,我创建了一个风格所有气缸均配有所需的钥匙,可以设置特殊功能来增强布局。

答案2

如果你也愿意考虑基于的解决方案asymptote,你可以考虑

 \documentclass{article}
 \usepackage[inline]{asymptote}
 \begin{document}
 \thispagestyle{empty}
 \begin{asy}
  import graph3;
  import solids;

  size(0,150);
  currentprojection=orthographic(1,1/2,1/2);

  // usage revolution r = cylinder(start,radius,length,ax);
  revolution r=cylinder(O,1,8,X);
  draw(surface(r),gray,render(merge=true));
  revolution r=cylinder((4,-4,0),1,8,Y);
  draw(surface(r),gray(0.8),render(merge=true));
 \end{asy}

 \begin{asy}
  import graph3;
  import solids;

  size(0,150);
  currentprojection=orthographic(1,1/2,1/2);

  // usage revolution r = cylinder(start,radius,length,ax);
  revolution r=cylinder(O,1,8,X);
  draw(surface(r),gray,render(merge=true));
  revolution r=cylinder((4,0,0),1,4,Y);
  draw(surface(r),gray(0.8),render(merge=true));
  draw((3.5,-1,1) -- (0,-1,1),  arrow=Arrow3(TeXHead2));
  draw((4.5,-1,1) -- (8,-1,1),  arrow=Arrow3(TeXHead2));
  label("$L_1$",(4,-1,1));
 \end{asy}
 \end{document}

在此处输入图片描述

据我所知,tikz目前还没有真正的 3D 引擎,这意味着人们必须或多或少地手动完成 3D 照明等工作,但我可能错了。我也不确定你是否真的想要网格(因为你的 MWE 中没有网格),但添加它并不太难。

相关内容