我想画一幅这样的画。
但我在透视(第 35 行)和圆柱体方面遇到了问题。
\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
这是否接近您想要实现的目标?
我所做的就是删除该tikz-3dplot
包,因为它会为您提供 3D 空间的正交投影。您提供的第一幅图像不是以正交投影绘制的,因此无法用 复制tikz-3dplot
。(另请参阅这和这为什么会这样,@土拨鼠在后者中。)
接下来,我手动设置x
、y
和z
基向量(我曾经\yangle
定义y
基向量,并在绘制圆柱体时使用该宏几次。)。
最后我只改变了你的圆柱体绘图代码,作为的功能\yangle
。
梅威瑟:
\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:请随意撤销以下更改:
\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}