4

I want to fill below of intersection of a plane and a cylinder of this picture, contain of arc AB and A'B' and below of polygon ABB'A' (fill form water). My code

\documentclass[border=2mm,12pt]{standalone}
\usepackage{tikz}
\usepackage{fouriernc}
\usepackage{tkz-euclide}
\usetkzobj{all}
\begin{document}
\newcommand{\boundellipse}[3]% center, xdim, ydim
{(#1) ellipse (#2 and #3)
}
\def\x{1}
\def\y{3}
\def\h{6}
\begin{tikzpicture}
\coordinate (O) at (0,0);
\coordinate (O') at (\h,0);
\coordinate (A) at ($(190:{\x} and {\y})$);
\coordinate (B) at ($(335:{\x} and {\y})$);
\tkzDefPointBy[translation=from O to O'](A){A'}
 \tkzGetPoint{A'}
 \tkzDefPointBy[translation=from O to O'](B)
 \tkzGetPoint{B'}
 \tkzDrawPoints[fill = black,size = 5 pt](O,A,B,A',B',O')
\tkzLabelPoint[above](O){$O$}
\tkzLabelPoints[left](A)
\tkzLabelPoints[right](O',B')
\tkzLabelPoints[below right](B)
\tkzLabelPoints[above left](A')
\tkzDrawPolygon(A,B,O)
\draw[thick] (B)--(B');
\draw[dashed] (A)--(A') (A')--(B')  (O)--(O') (O')--(A') (O')--(B');
\draw[thick] \boundellipse{0,0}{\x cm}{\y cm};
\draw [dashed] (\h cm,\y cm) arc (90:270:\x cm and \y cm);
\draw [thick] (\h cm,-\y cm) arc (-90:90:\x cm and \y cm);
\draw[thick] (0,\y cm)--(\h cm,\y cm);
\draw[thick] (0,-\y cm)--(\h cm,-\y cm);
\tkzFillPolygon[pattern color=blue, pattern=vertical lines](A,B,B',A')
\end{tikzpicture}
\end{document} 

enter image description here

How can I fill?

1

I would use tikz-3dplot for this. You can then use 3d coordinates and change the view etc.

\documentclass[border=2mm,12pt,tikz]{standalone}
\usepackage{tikz-3dplot} 
\usetikzlibrary{3d,calc,backgrounds}
\usepackage{fouriernc}
%% smuggling from https://tex.stackexchange.com/a/470979/121799
\newcounter{smuggle}
\DeclareRobustCommand\smuggleone[1]{%
    \stepcounter{smuggle}%
    \expandafter\global\expandafter\let\csname smuggle@\arabic{smuggle}\endcsname#1%
    \aftergroup\let\aftergroup#1\expandafter\aftergroup\csname smuggle@\arabic{smuggle}\endcsname
}
\DeclareRobustCommand\smuggle[2][1]{%
    \smuggleone{#2}%
    \ifnum#1>1
    \aftergroup\smuggle\aftergroup[\expandafter\aftergroup\the\numexpr#1-1\aftergroup]\aftergroup#2%
    \fi
}
\begin{document}
% please do not use \x and \y since these are used in the calc syntax
\def\myx{1}
\def\myy{3}
\def\h{6}

\tdplotsetmaincoords{83}{70}
\begin{tikzpicture}[tdplot_main_coords]
%    \draw[-latex] (0,0,0) -- (1,0,0) node[pos=1.1]{$x$};
%    \draw[-latex] (0,0,0) -- (0,1,0) node[pos=1.1]{$y$};
%    \draw[-latex] (0,0,0) -- (0,0,1) node[pos=1.1]{$z$};
  \begin{scope}[canvas is xz plane at y=0]
   \draw[thick] (0,0) coordinate[label=above:$O$] (O) circle (\myy);
  \end{scope}
  \begin{scope}[canvas is xz plane at y=\h]
   \path (0,0) coordinate[label=above:$O'$] (O');   
   \draw[thick] let \p1=($(O')-(O)$),\n1={atan2(\y1,\x1)} in
    \pgfextra{\pgfmathsetmacro{\myangle}{\n1}\smuggle{\myangle}} 
    ($(O)+({90+\n1}:\myy)$) --
    ({90+\n1}:\myy) arc({90+\n1}:{-90+\n1}:\myy) --
    ($(O)+({-90+\n1}:\myy)$) ;
   \begin{scope}[on background layer,every label/.append style={black}]
     \draw[dashed] ({90+\myangle}:\myy) arc({90+\myangle}:{180+90+\myangle}:\myy); 
     % front
     \shade[top color=blue!30,bottom color=blue,shading angle=\myangle] 
      ($(O)+({-20}:\myy)$) -- ($(O')+({-20}:\myy)$) 
      arc(-20:-90+\myangle:\myy) --($(O)+({-90+\myangle}:\myy)$)
      arc(-90+\myangle:-20:\myy);
      % left
     \shade let \p1=($({-160}:\myy)-({-20}:\myy)$),\n1={180+atan2(\y1,\x1)} in
      [top color=blue!30,bottom color=blue,shading angle=\n1]
      ($(O)+({-20}:\myy)$) arc(-20:-160:\myy) -- cycle;
     %top 
     \fill[blue!20]  ($(O')+({-20}:\myy)$) coordinate[label=right:$B'$](B') 
      -- ($(O')+({-160}:\myy)$) coordinate[label=above left:$A'$](A') 
      -- ($(O)+({-160}:\myy)$) coordinate[label=left:$A$](A) 
      -- ($(O)+({-20}:\myy)$) coordinate[label=right:$B$](B) 
      -- cycle;
   \end{scope}
  \end{scope}
  \draw[dashed] (O) -- (O') -- (B') -- (A')   (A) -- (A') -- (O');
  \draw (B) -- (A) -- (O) -- (B) -- (B');
  \foreach \X in {A,B,O}
  {\fill (\X) circle(1pt) (\X') circle(1pt);}
\end{tikzpicture}
\end{document} 

enter image description here

3

Cylindrical tank

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\newcommand{\alp}{60}
\newcommand{\bet}{30}
\fill[gray!20,opacity=.5] ({.5*cos(270+\bet)},{sin(270+\bet)}) -- ({.5*cos(270-\alp)},{sin(270-\alp)}) arc ({270-\alp}:{270+\bet}:.5 and 1);
\fill[gray!15] ({.5*cos(270-\alp)},{sin(270-\alp)}) --             ({2+.5*cos(270-\alp)},{sin(270-\alp)}) 
--({2+.5*cos(270+\bet)},{sin(270+\bet)}) 
--({.5*cos(270+\bet)},{sin(270+\bet)}) 
 --  cycle;
    \fill[gray!20] (
{.5*cos(270+\bet)},
{sin(270+\bet)}
) -- 
(
{2+.5*cos(270+\bet)},
{sin(270+\bet)}
)
arc ({270+\bet}:270:.5 and 1) -- (0,-1) -- cycle;
\draw[gray] (0,0) ellipse (.5 and 1);
\draw[gray] (2,-1) arc (-90:90:.5 and 1);
\draw[gray!20] (2,-1) arc (-90:-270:.5 and 1);
\draw[gray] (0,1) -- (2,1);
\draw[gray] (0,-1) -- (2,-1);
\end{tikzpicture}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.