2

I want to draw a picture like this.

enter image description here

But I take on problems in terms of perspective (line 35) and the cylinder.

enter image description here

\documentclass[border=10pt]{standalone}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[x11names,dvipsnames,svgnames]{xcolor}
\definecolor{rusia}{RGB}{85 85 57}
\definecolor{brightcerulean}{rgb}{0.11, 0.67, 0.84}
\definecolor{brandeisblue}{rgb}{0.0, 0.44, 1.0}
\usepackage[indonesian]{babel}
\usepackage{fouriernc}
\usepackage{amsmath,amssymb}
\let\ds\displaystyle
\usepackage{tikz}
\usetikzlibrary{calc,patterns,intersections,decorations.pathmorphing}

\usepackage{adjustbox}
\usepackage[labelformat=simple,labelfont=footnotesize,font=footnotesize,hypcap=false,skip=3pt]{caption}
\usepackage{tikz-3dplot}
\usetikzlibrary{3d}

% fix wrong implementation of xy canvas
\makeatletter
\tikzoption{canvas is xy plane at z}[]{%
  \def\tikz@plane@origin{\pgfpointxyz{0}{0}{#1}}%
  \def\tikz@plane@x{\pgfpointxyz{1}{0}{#1}}%
  \def\tikz@plane@y{\pgfpointxyz{0}{1}{#1}}%
  \tikz@canvas@is@plane
}
\makeatother

\begin{document}

\tdplotsetmaincoords{86}{50} % pengaturan sudut pandang (persfektif)
\begin{tikzpicture}[tdplot_main_coords]
\coordinate (A) at (0,0,0);
\coordinate (B) at (0,4,0);
\coordinate (C) at (5,4,0);
\coordinate (D) at (0,0,2.5);
\coordinate (E) at (0,4,1.3);
\coordinate (F) at (5,4,1.75);
\draw[very thin,canvas is xy plane at z=0,darkgray!40] (0,0) grid (5,4);
\draw[ultra thin,gray] (D)--(A)--(B)--(C)--(F);

\begin{scope}[decoration={zigzag,segment length = 1.74cm, amplitude =1mm}]
\shade  (A)--(D) decorate {-- (E)}--(B)--cycle ;
\shade  (B)--(E) decorate {-- (F)}--(C)--cycle ;
\end{scope}

\shade[canvas is yz plane at x=.5,top color=white,bottom color=brandeisblue] (1,0)--(2,0) arc(-90:90:.2)--(1,.4) arc(90:-90:.2);
\shade[canvas is yz plane at x=.5,ball color=Cerulean!50, shading angle=225] (1,.2) circle (.2);

\path[decoration = {zigzag,segment length = 1.74cm, amplitude =1mm},decorate] (D)--(E);
\path[decoration = {zigzag,segment length = 1.74cm, amplitude =1mm},decorate] (E)--(F);

\draw[very thin,canvas is yz plane at x=.5,brandeisblue!70] (1,0)--(2,0) (2,.4)--(1,.4) 
(1,.2) circle (.2) (2,0) arc(-90:90:.2);
\end{tikzpicture}

\end{document}

1 Answer 1

2

Does this come anywhere close to what you would want to achieve?

enter image description here

What I did was removing the tikz-3dplot package, because it will give you an orthographic projection of 3D space. The first image you provided is not drawn in an orthographic projection, so it is impossible to replicate with tikz-3dplot. (See also this and this question for why that is, explained expertly by @marmot in the latter.)

Next I set the x, y, and z base vectors manually (I used \yangle to define the y base vector, and use that macro a few times in drawing the cylinder.).

Finally I only changed your cylinder drawing code, as function of \yangle.

MWE:

\documentclass[border=10pt]{standalone}

\usepackage[x11names,dvipsnames,svgnames]{xcolor}
\definecolor{rusia}{RGB}{85 85 57}
\definecolor{brightcerulean}{rgb}{0.11, 0.67, 0.84}
\definecolor{brandeisblue}{rgb}{0.0, 0.44, 1.0}

\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}

\usetikzlibrary{3d}

% fix wrong implementation of xy canvas
\makeatletter
\tikzoption{canvas is xy plane at z}[]{%
  \def\tikz@plane@origin{\pgfpointxyz{0}{0}{#1}}%
  \def\tikz@plane@x{\pgfpointxyz{1}{0}{#1}}%
  \def\tikz@plane@y{\pgfpointxyz{0}{1}{#1}}%
  \tikz@canvas@is@plane
}
\makeatother

\begin{document}

\pgfmathsetmacro\yangle{30}

\begin{tikzpicture}[
    y={({0.5*cos(\yangle)*1cm},{0.5*sin(\yangle)*1cm})},
    x={(1cm,0cm)},
    z={(0cm,1cm)}
]
\coordinate (A) at (0,0,0);
\coordinate (B) at (0,4,0);
\coordinate (C) at (5,4,0);
\coordinate (D) at (0,0,2.5);
\coordinate (E) at (0,4,1.3);
\coordinate (F) at (5,4,1.75);
\draw[very thin,canvas is xy plane at z=0,darkgray!40] (0,0) grid (5,4);
\draw[ultra thin,gray] (D)--(A)--(B)--(C)--(F);

\begin{scope}[decoration={zigzag,segment length = 1.74cm, amplitude =1mm}]
\shade  (A)--(D) decorate {-- (E)}--(B)--cycle ;
\shade  (B)--(E) decorate {-- (F)}--(C)--cycle ;
\end{scope}

\shade[top color=white,bottom color=brandeisblue,shading angle=45] (0.2,1,0.2) ++({0.2*cos(\yangle+90)},0,{0.2*sin(\yangle+90)}) -- ++(0,1,0) arc (\yangle+90:\yangle-90:0.2cm) -- ++(0,-1,0) arc (\yangle-90:\yangle+90:0.2cm);
\shade[ball color=Cerulean!50, shading angle=225] (0.2,1,0.2) circle (0.2cm);

\path[decoration = {zigzag,segment length = 1.74cm, amplitude =1mm},decorate] (D)--(E);
\path[decoration = {zigzag,segment length = 1.74cm, amplitude =1mm},decorate] (E)--(F);

\draw[very thin,brandeisblue!70] (0.2,1,0.2) circle (0.2cm) ++({0.2*cos(\yangle+90)},0,{0.2*sin(\yangle+90)}) -- ++(0,1,0) arc (\yangle+90:\yangle-90:0.2cm) -- ++(0,-1,0);

\end{tikzpicture}

\end{document}

@Max: please feel free to revert the changes that follow:

\documentclass[border=10pt]{standalone}

\usepackage[x11names,dvipsnames,svgnames]{xcolor}
\definecolor{rusia}{RGB}{85 85 57}
\definecolor{brightcerulean}{rgb}{0.11, 0.67, 0.84}
\definecolor{brandeisblue}{rgb}{0.0, 0.44, 1.0}

\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}

\usetikzlibrary{3d}

% fix wrong implementation of xy canvas
\makeatletter
\tikzoption{canvas is xy plane at z}[]{%
  \def\tikz@plane@origin{\pgfpointxyz{0}{0}{#1}}%
  \def\tikz@plane@x{\pgfpointxyz{1}{0}{#1}}%
  \def\tikz@plane@y{\pgfpointxyz{0}{1}{#1}}%
  \tikz@canvas@is@plane
}
\makeatother

\begin{document}

\pgfmathsetmacro\yangle{30}

\begin{tikzpicture}[
    y={({0.5*cos(\yangle)*1cm},{0.5*sin(\yangle)*1cm})},
    x={(1cm,0cm)},
    z={(0cm,1cm)}
]
\coordinate (A) at (0,0,0);
\coordinate (B) at (0,4,0);
\coordinate (C) at (5,4,0);
\coordinate (D) at (0,0,2.5);
\coordinate (E) at (0,4,1.3);
\coordinate (F) at (5,4,1.75);
\draw[very thin,canvas is xy plane at z=0,darkgray!40] (0,0) grid (5,4);
\draw[ultra thin,gray] (D)--(A)--(B)--(C)--(F);

\begin{scope}[decoration={zigzag,segment length = 1.74cm, amplitude =1mm}]
\shade  (A)--(D) decorate {-- (E)}--(B)--cycle ;
\shade  (B)--(E) decorate {-- (F)}--(C)--cycle ;
\end{scope}

\draw[thick,opacity=0.3] (0.2,1.5,0) -- ++ (0.5,0,0) coordinate (rod end);

\shade[top color=white,bottom color=brandeisblue,shading angle=45] (0.2,1,0.2) ++({0.2*cos(\yangle+90)},0,{0.2*sin(\yangle+90)}) -- ++(0,1,0) arc (\yangle+90:\yangle-90:0.2cm) -- ++(0,-1,0) arc (\yangle-90:\yangle+90:0.2cm);
\shade[ball color=Cerulean!50, shading angle=225] (0.2,1,0.2) circle (0.2cm);

\path[decoration = {zigzag,segment length = 1.74cm, amplitude =1mm},decorate] (D)--(E);
\path[decoration = {zigzag,segment length = 1.74cm, amplitude =1mm},decorate] (E)--(F);

\draw[very thin,brandeisblue!70] (0.2,1,0.2) circle (0.2cm) ++({0.2*cos(\yangle+90)},0,{0.2*sin(\yangle+90)}) -- ++(0,1,0) arc (\yangle+90:\yangle-90:0.2cm) -- ++(0,-1,0);

\begin{scope}
\clip (0.2,1,0.2) ++({0.2*cos(\yangle+90)},0,{0.2*sin(\yangle+90)}) -- ++(0,1,0) arc (\yangle+90:\yangle-90:0.2cm) -- ++(0,-1,0) arc (\yangle-90:\yangle+90:0.2cm);
\draw[thick,opacity=0.3,line cap=round] (0.2,1.5,0.2) ++({0.2*cos(\yangle+90)},0,{0.2*sin(\yangle+90)})  arc (\yangle+90:\yangle-90:0.2cm);
\end{scope}
\path (0.2,1,0.2) ++({-0.2*cos(\yangle+90)},0.5,{0.2*sin(\yangle+90)}) --
(rod end) coordinate[pos=-1] (rod start);
\draw[thick] (rod start) -- (rod end);

\end{tikzpicture}

\end{document}

enter image description here

4
  • @Max Sorry, I haven't drawn the wood, it should be.
    – kalakay
    Commented Oct 23, 2018 at 15:02
  • 1
    @kalakay If you also want the wooden stick and the accompanying shadows drawn, you might want to switch to more realistic alternatives such as asymptote. It might prove difficult to do that with Tikz.
    – Max
    Commented Oct 23, 2018 at 15:52
  • 1
    @Max Please feel free to revert the edit I made. (I am not 100% it is easy to convince asymptote to draw a highly non-orthographic projection, but you are right that if this can be done, the shadows and so on will be more straightforward than in TikZ.)
    – user121799
    Commented Oct 23, 2018 at 16:48
  • 1
    @marmot Thanks for the edit, looks very nice!
    – Max
    Commented Oct 23, 2018 at 18:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .