4

I can draw the black part in the picture, but I cant rotate with angle alpha and draw the red part and fill it. Also, it is obvious, two side of figure rotate, and one side is fix, and the other one just shift in the z direction.

my code: enter image description here

change to: enter image description here

\documentclass{standalone}
‎\usepackage{tikz,tikz-3dplot}‎‎
\begin{document}‎‎
\begin{tikzpicture}
\draw[->] (0,0,0)--++(5,0,0) node[right]{$x$};
\draw[->] (0,0,0)--++(0,5,0) node[above]{$y$};
\draw[->] (0,0,0)--++(0,0,8) node[below left]{$z$};
\draw[ultra thick] (4,0,0) arc[start angle=0, end angle=60, radius=4] --++(0,0,8.5) arc[start angle=60, end angle=0, radius=4]--cycle;
‎\filldraw[ fill=blue‎, ‎nearly transparent‎, ,‎looseness=.6](4,0,0) arc[start angle=0, end angle=60, radius=4] --++(0,0,8.5) arc[start angle=60, end angle=0, radius=4]--cycle;
\end{tikzpicture}
\end{document}
  • To be honest, I have no idea what you are asking. Could you clarify your question somehow? I understand you want to fill something in red, but that's about it. If you are hoping to treat the cylinder as a 3D object which you can rotate, however, you are using the wrong software. TikZ can't do that. You cannot have it rotate a 3D object. You can fake 3D in 2D but when you rotate something, you have to recalculate everything to fake the new situation in 2D. – cfr Jan 9 '16 at 1:51
  • Also, your code does not correspond to the image you posted. But that image does not seem to be what you are trying to draw either as nothing there is filled in red. So what exactly is the status of that image and how does it relate to (1) the code and (2) what you are trying to draw? – cfr Jan 9 '16 at 1:54
  • Thank you, in one word, I want to draw red part on the above picture. – sayros Jan 9 '16 at 2:04
  • Your code does not compile for me. It has all kinds of strange invisible characters in it. Please fix it so that it can be copy-paste-compiled without needing to sift it for strange hidden problems. Thanks. – cfr Jan 9 '16 at 2:14
  • Thank you again, I fix it, and result of my code figure are as above. – sayros Jan 9 '16 at 2:30
4

I'm not sure this will be much help. [But see below for a rotated version which might be more useful, at least.] You need somebody who knows a bit more (read 'anything') about the package tikz-3dplot. This is more by way of my initial experiment than an answer.

As I understand it (which is not very well at all), the package works on the basis of different coordinate systems. So the idea is that to draw an arc in 3d, you need to figure out the right x'y' plane to tell TikZ to draw in, because TikZ can only draw arcs in 2d - not 3. So one thing the package does is provide a command which calculates this plane given an angle.

\tdplotsetthetaplanecoords{30}

This effectively sets up a system of rotated coordinates which lets you draw stuff with the arcs in the appropriate x'y' plane.

... I think ...

To use this, you need to set up the main, non-rotated coordinate system first.

\tdplotsetmaincoords{45}{150}

This choice was somewhat arbitrary. Doubtless you'll want different values. This sets up the main coordinate system which is rotated about the z and x axes by the specified amounts.

\tdplotsetmaincoords{45}{150}
\begin{tikzpicture}[tdplot_main_coords]
  \draw[->] (0,0,0) -- (5,0,0) node[anchor=north east]{$x$};
  \draw[->] (0,0,0) -- (0,5,0) node[anchor=north west]{$y$};
  \draw[->] (0,0,0) -- (0,0,8) node[anchor=south]{$z$};
\end{tikzpicture}

axes in main coordinate system

So then we can draw and fill the non-rotated shape.

  \draw [ultra thick, preaction={fill=blue, nearly transparent}] (4,0,0) arc[start angle=0, end angle=60, radius=4] -- ++(0,0,8.5) arc[start angle=60, end angle=0, radius=4] coordinate [pos=.75] (a) -- cycle;

initial position

Then we specify the rotated coordinate system using whatever angle e.g. 30.

  \tdplotsetthetaplanecoords{30}

Now if we draw, the coordinates will be relative to the rotated system. I think. So we just need to compensate for the different positions on the circle when we are ending and starting arcs by adding 30 to the values used in the first \draw command.

  \draw [ultra thick, preaction={fill=red, nearly transparent}] (4,0,0) arc[start angle=30, end angle=90, radius=4] -- ++(0,0,8.5) arc[start angle=90, end angle=30, radius=4] coordinate [pos=.75] (b)  -- cycle;

rotated

Finally, we can add the angle a bit crudely on top.

  \draw [green, ultra thick, ->] (a) [bend right]to (b)  node [above] {$\alpha$};

rotated with angle marked

Complete code:

\documentclass[border=5pt, multi, tikz]{standalone}
\usepackage{tikz-3dplot}
\begin{document}
\tdplotsetmaincoords{45}{150}
\begin{tikzpicture}[tdplot_main_coords]
  \draw[->] (0,0,0) -- (5,0,0) node[anchor=north east]{$x$};
  \draw[->] (0,0,0) -- (0,5,0) node[anchor=north west]{$y$};
  \draw[->] (0,0,0) -- (0,0,8) node[anchor=south]{$z$};
  \draw [ultra thick, preaction={fill=blue, nearly transparent}] (4,0,0) arc[start angle=0, end angle=60, radius=4] -- ++(0,0,8.5) arc[start angle=60, end angle=0, radius=4] coordinate [pos=.75] (a) -- cycle;
  \tdplotsetthetaplanecoords{30}
  \draw [ultra thick, preaction={fill=red, nearly transparent}] (4,0,0) arc[start angle=30, end angle=90, radius=4] -- ++(0,0,8.5) arc[start angle=90, end angle=30, radius=4] coordinate [pos=.75] (b)  -- cycle;
  \draw [green, ultra thick, ->] (a) [bend right]to (b)  node [above] {$\alpha$};
\end{tikzpicture}
\end{document}

EDIT

You might be able to rotate the picture as you wish by rotating the regular TikZ coordinate system using rotate around <axis>=<angle> as shown by Ktree here. For example, if I change the tikz-3d main coordinate transformation to

\tdplotsetmaincoords{-35}{0}

and use

rotate around y=-10

then, making appropriate adjustments for drawing the angle and labelling the axes, the following result can be obtained:

rotated diagram

Complete code:

\documentclass[border=5pt, multi, tikz]{standalone}
\usepackage{tikz-3dplot}
\begin{document}
\tdplotsetmaincoords{-35}{0}
\begin{tikzpicture}[tdplot_main_coords]
  \begin{scope}[rotate around y=-10]
    \draw[->] (0,0,0) -- (5,0,0) node[anchor=west]{$x$};
    \draw[->] (0,0,0) -- (0,5,0) node[anchor=south]{$y$};
    \draw[->] (0,0,0) -- (0,0,8) node[anchor=north]{$z$};
    \draw [ultra thick, preaction={fill=blue, nearly transparent}] (4,0,0) arc[start angle=0, end angle=60, radius=4] coordinate [pos=.25] (a) -- ++(0,0,8.5) arc[start angle=60, end angle=0, radius=4] -- cycle;
    \tdplotsetthetaplanecoords{30}
    \draw [ultra thick, preaction={fill=red, nearly transparent}] (4,0,0) arc[start angle=30, end angle=90, radius=4] coordinate [pos=.2] (b) -- ++(0,0,8.5) arc[start angle=90, end angle=30, radius=4]  -- cycle;
    \draw [green!75!black, ultra thick, <->] (a) [bend right] to (b);
    \node [green!75!black, yshift=5pt, anchor=south] at (b) {$\alpha$};
  \end{scope}
\end{tikzpicture}
\end{document}
  • I think you could "rotate" the plane to look like his image, cfr. – Alenanno Jan 9 '16 at 11:52
  • @Alenanno Do you mean use two rotated coordinate systems and ignore the main one? I couldn't find an example in the documentation which had the z axis anything but on the straight vertical line, if that makes sense. – cfr Jan 9 '16 at 23:35
  • I meant, his image is "laying" while yours is standing, so to speak. :P – Alenanno Jan 9 '16 at 23:42
  • @Alenanno I know that. What I'm not sure about is how to make it lie down quietly! – cfr Jan 9 '16 at 23:46
  • @Alenanno Were you thinking of something like this? – cfr Jan 10 '16 at 0:09
2

In question1 (duplicate of question here), I show a solution using scopes for the rotations and save path to achieve the filling. This is

  • complicated and
  • the path is not connected, so the corners might look ugly.

I found a much easier solution when I understood how to apply transformations only to a part of a path:

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
    %coordinate system
    \draw[->] (0,0,0)--++(5,0,0) node[right]{$x$};
    \draw[->] (0,0,0)--++(0,5,0) node[above]{$y$};
    \draw[->] (0,0,0)--++(0,0,10) node[below left]{$z$};

    % cylinder:
    \draw[preaction={fill=blue,very  nearly transparent}](4,0,0) 
                arc[start angle=0, end angle=90, radius=4]node[inner sep=0](n11){}
                -- ++(0,0,8.5)node[inner sep=0](n21){}
                arc[start angle=90, end angle=0, radius=4] -- cycle;
    \draw[](n21.center)--(0,0,8.5)--(4,0,8.5);
    \draw[](0,4,0)--(n11.center);

    % skew cylinder
    \draw[ultra thick, preaction={fill=red,nearly transparent}] (4,0,0) 
        {[rotate around x=30]arc[start angle=0, end angle=90, radius=4]node[inner sep=0](n1){}} 
        -- ++(0,0,8.5) node[inner sep=0](n2){}
        {[rotate around x=30]arc[start angle=90, end angle=0, radius=4]} -- cycle;
    % the connections
    \draw[ultra thick](n2.center)--(0,0,8.5)--(4,0,8.5);
    \draw[thick, dashed](0,4,0)--(n1.center);
\end{tikzpicture}
\end{document}

skew cylinder

  • Very nice! A bit more. – cfr Jan 15 '16 at 22:12
  • @cfr A bit more? – Ktree Jan 18 '16 at 6:28
  • 'Very nice!' is too short - more characters are needed for the system to accept the comment. 'A bit more.' did the trick. – cfr Jan 18 '16 at 20:33
  • :D didn't know that. Enough – Ktree Jan 18 '16 at 20:34

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.