0

I want to draw below picture. How can we calculate the tangle angle automically. enter image description here

%https://tex.stackexchange.com/questions/564162/drawing-half-cylinder-under-a-pyramid-through-tikz

Thank you in advance!

MWE

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{3d,perspective}
\begin{document}
\begin{tikzpicture}[rotate around y=60]
\def\radius{2}
\def\height{4}
\def\mark{0.2}
\def\ang{60}
\draw[thick] (-\radius,0,\radius) -- (\radius,0,\radius) -- (\radius,0,-\radius)--(-\radius,0,-\radius)--cycle;
\begin{scope}[rotate around y=-90,shift={(\radius,0,\radius)}]
  \draw[thick] (0,0,0) arc(0:-180:\radius);
\end{scope}
\begin{scope}[rotate around y=90,shift={(\radius,0,\radius)}]
  \draw[densely dashed, thick,black!80] (0,0,0) arc(0:-180+\ang:\radius);
\end{scope}
\begin{scope}[rotate around y=-90,shift={(\radius,0,-\radius)}]
  \draw[thick] (0,0,0) arc (0:-\ang:\radius) -- ++(0,0,2*\radius);
\end{scope}
\end{tikzpicture}
\end{document}

Another method which I have write

\documentclass[border=3pt,tikz]{standalone}
\usetikzlibrary{calc,angles}
\begin{document}
\begin{tikzpicture}[declare function={goc=10;r=2.5;l=4;}]
  \draw ({180-goc}:r)  arc ({180-goc}:{360-goc}:r);
  \draw[shift={(l,0)}] (270:r) arc ({270}:{360-goc}:r)
  ({180-goc}:r) coordinate (A) arc ({180-goc}:{180+0.25*goc}:r);
  \draw[shift={(l,0)},dashed] ({180+0.25*goc}:r) arc ({180+0.25*goc}:{270-goc}:r);
  \draw (270:r)--+(l,0)
  ({360-goc}:r)--({180-goc}:r)--+(l,0)
  ({360-goc}:r)--+(l,0)--(A);
\end{tikzpicture}
\end{document}
  • If I'm reading your question right, then you're asking about drawing the bottom line correctly. That's part of what I do in my answer here for full cylinders: https://tex.stackexchange.com/a/31606/86 – Andrew Stacey Jun 26 '22 at 08:49
  • 1
    @AndrewStacey Thank you for your sugguest. Another difficult problem is angle to control dashed curve. – Nam Tran Le Jun 26 '22 at 09:12

4 Answers4

2

Purely for comparison, here is a simple Metapost version of your diagram. But I hasten to add that MP does not have any built-in support for 3D work -- I've used the geometry of the halfcircle path to work out the hidden lines in this simple drawing.

\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
beginfig(1);
    path a, b; 
    numeric r; r = 13;
    a = halfcircle rotated (180-r) scaled 144 -- cycle;
    b = a shifted 300 right;
numeric s, t; 
s = 2r / 45;
t = directiontime right of a;

draw subpath (0, s) of b withpen pencircle scaled 1/4;
draw subpath (s, t) of b dashed evenly scaled 1/2 withcolor 3/4;
draw subpath (t, 5) of b;
for $ = 0, t, 4:
    draw point $ of a -- point $ of b;
endfor
draw a; 
for $ = a, b:
    draw point -1/2 of $ withpen pencircle scaled 2;
endfor

label.llft("$r=" & decimal r & "$", urcorner currentpicture); 

endfig; \end{mplibcode} \end{document}

This is wrapped up in luamplib so you need to compile it with lualatex. Here is the output for various values of the r parameter:

half cylinder rotated 13

half cylinder rotated 21

half cylinder rotated 34

Thruston
  • 42,268
1

A sketch, rather than a complete solution. What you want to use is \usetikzlibrary{intersections} .

There are several posts in intersections here, where this one might be quite educational: Can someone help me doing 2 points of intersection? . See also the pgf-manual, chapter 13.3.2 Intersections of Arbitrary Paths , p. 144ff.

If you want to transfer the solution from the link to your code, I suggest to single out and name the two paths (lines) and the arc you want to intersect with. The intersection points can be used to draw the straddled or dashed lines next, so I'd rearrange the order of \draw commands, too. May be, your function becomes obsolete?

Sketch towards the solution, with manual edits:

sketch toward the solution

% ~~~ analysing existing code ~~~~~~~~
\documentclass[border=3pt]{standalone}

\usepackage{tikz} %\usetikzlibrary{calc, angles} \usetikzlibrary{intersections}% <<<

\begin{document}

\begin{tikzpicture}[declare function={goc=10;r=2.5;l=4;}] \draw ({180-goc}:r) arc ({180-goc}:{360-goc}:r); % ~~~ visible arcs in the back ~~~~ \draw[shift={(l,0)}] (270:r) arc ({270}:{360-goc}:r) ({180-goc}:r) coordinate (A) arc ({180-goc}:{180+0.25*goc}:r);

% ~~~ too many lines drawn at ones wrt. intersections ~~~~~~~~~~ \draw [red] (270:r)--+(l,0) % line at bottom ({360-goc}:r)--({180-goc}:r)--+(l,0)% upper right 2 lines ({360-goc}:r)--+(l,0)--(A)% upper left 2 lines ; % ~~~ dashed part in the back ~~~~~ \draw[shift={(l,0)},dashed] ({180+0.25goc}:r) arc ({180+0.25goc}:{270-goc}:r);

\end{tikzpicture}

\end{document}

MS-SPO
  • 11,519
1

Trying to take the posters last answer one step further. Changes I introduced:

  • used article, as I'm going to draw more than one shape
  • moving the tikz-code to a new macro, called halfcycl; notice the %-signs at the end of each line
  • introducing some \def statements; idea is to be able to "change in one place only" and to reduce some visual noise by using "constants"
  • added some comments to better follow your drawings
  • finally, making several calls to halfcycle, with varying parameters, printed in front

Result: So it works fine many times, and leaves some room for improvement.

Result

%\documentclass[border=3pt,tikz]{standalone}
\documentclass[12pt]{article}
\usepackage{tikz}

\newcommand\halfcyl[3]{% goc / r / L \begin{tikzpicture}[declare function={goc=#1;r=#2;L=#3;},line join=round]% % defining a few constants ~~~~~~~~~~ \def\lpa{{180-goc}}% left polar angle \def\rpa{{360-goc}}% right polar angle \def\vec{(L,0)}% shift vector; replaced l by L to avoid mistake with 1

% defining coordinates ~~~~~~~~~~~
\path (\lpa:r) coordinate (A)%
    (\rpa:r) coordinate (B)%
    ({362-goc}:r) coordinate (Bt)%
    ([shift={\vec}]A) coordinate (D)%
    ([shift={\vec}]B) coordinate (C)%
    ([shift={\vec}]Bt) coordinate (Ct)%
    (270:r) coordinate (E)%
    ([shift={\vec}]E) coordinate (F)%
    ;

% left solid part from back ~~~~~~~~~~~~
\begin{scope}%
    \clip (A)--(Bt)--(Ct)--(D)--cycle;%
    \draw[shift={\vec}] (\lpa:r) arc (\lpa:{270}:r);%
\end{scope}%

% providing the dashed circular part ~~~~~~~~
\begin{scope}%
    \clip (E)--(B)--(C)--(F)--cycle;%
    \draw[densely dashed, shift={\vec}] (\lpa:r) arc (\lpa:{270}:r);%
\end{scope}%

%right solid circle from back ~~~~~~~~~~~~~
\draw[shift={\vec}] (270:r) arc ({270}:\rpa:r);%

% all parts from front ~~~~~~~~~~~
\draw (\lpa:r) arc (\lpa:\rpa:r)%
    (A)--(B)--(C)--(D)--cycle%
    (E)--(F);%

\end{tikzpicture}% }

\begin{document} goc / r / L

13 / 1.5 / 5 \halfcyl{13}{1.5}{5}

36 / 3 / 2  \halfcyl{36}{3}{2}

50 / 2 / 4  \halfcyl{50}{2}{4}

-10 / 2 / 4 \halfcyl{-10}{2}{4}

\end{document}

MS-SPO
  • 11,519
0

This code can draw with slanted angle automatically. But it is not an orthogonal projection in space.

\documentclass[border=3pt,tikz]{standalone}
\begin{document}
\begin{tikzpicture}[declare function={goc=13;r=1.5;l=5;},line join=round]
\path ({180-goc}:r) coordinate (A)
({360-goc}:r) coordinate (B)
({362-goc}:r) coordinate (Bt)
([shift={(l,0)}]A) coordinate (D)
([shift={(l,0)}]B) coordinate (C)
([shift={(l,0)}]Bt) coordinate (Ct)
(270:r) coordinate (E)
([shift={(l,0)}]E) coordinate (F)
;
\begin{scope}
\clip (A)--(Bt)--(Ct)--(D)--cycle;
\draw[shift={(l,0)}] ({180-goc}:r) arc ({180-goc}:{270}:r);
\end{scope}
\begin{scope}
\clip (E)--(B)--(C)--(F)--cycle;
\draw[densely dashed, shift={(l,0)}] ({180-goc}:r) arc ({180-goc}:{270}:r);
\end{scope}
\draw[shift={(l,0)}] (270:r) arc ({270}:{360-goc}:r);
\draw ({180-goc}:r) arc ({180-goc}:{360-goc}:r)
(A)--(B)--(C)--(D)--cycle
(E)--(F);
\end{tikzpicture}
\end{document}