对于一些数学项目,我试图画一个篮子,如下图所示,
我已经画出篮子的一些线条,见下图,这是 MWE 之后的,但是我仍然在努力画出一些正确的阴影,主要是手柄上的阴影。我正在寻找球体部分的阴影,但到目前为止还没有找到任何东西。有人能帮忙吗?
\documentclass{standalone}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usepackage{tikz-cd}
\usepackage[]{calc}
\tdplotsetmaincoords{70}{0}
\begin{document}
\begin{tikzpicture}[scale=5,tdplot_main_coords]
\coordinate (O) at (0,0,0);
\tdplotsetrotatedcoords{90}{90}{0}
\tdplotdrawarc[fill = gray, tdplot_rotated_coords]{(O)}{1}{-90}{90}{}{}
\tdplotdrawarc[fill = lightgray, tdplot_main_coords]{(O)}{1}{0}{360}{}{}
\tdplotsetrotatedcoords{-160}{90}{180}
\tdplotdrawarc[tdplot_rotated_coords]{(0,0,.2)}{1}{-89.5}{90.5}{}{}
\tdplotdrawarc[tdplot_rotated_coords]{(0,0,-.2)}{1}{-89.5}{90.5}{}{}
\end{tikzpicture}
\end{document}
答案1
欢迎来到 TeX.SE!!
另一种方法,使用Tiisometric view
中的选项perspective
钾Z 库和3d
库。我把手柄做成了圆柱形,几乎没有什么区别,而且这样更简单。
像这样:
\documentclass[tikz,border=1.618mm]{standalone}
\usetikzlibrary{3d,perspective}
\begin{document}
\begin{tikzpicture}[isometric view,rotate around z=180,line cap=round,line join=round]
\def\w{0.15} % handle width
\pgfmathsetmacro\a{asin(\w)} % handle angle
\pgfmathsetmacro\r{sqrt(1-\w*\w)} % handle radius
\draw[fill=gray!30] (-45:1) arc (-45:135:1) arc (0:-180:1cm);
\draw[bottom color=gray,top color=gray!40] (0,0) circle (1);
\path[canvas is yz plane at x=-\w] (\r,0) arc (0:135:\r) coordinate (T); % tangent point
% inner handle
\draw[bottom color=gray!40] (270-\a:1) arc (270-\a:270+\a:1)
{[canvas is yz plane at x=\w] arc (180:135:\r) -- (T) arc (135:180:\r)};
% outer handle
\draw[fill=gray!30] (90+\a:1) arc (90+\a:90-\a:1)
{[canvas is yz plane at x=\w] (\r,0) arc (0:135:\r) -- (T) arc (135:0:\r)};
\end{tikzpicture}
\end{document}
答案2
计算视角相当简单,因此允许任意视角。
\documentclass[tikz,border=2mm]{standalone}
\usepackage{tikz-3dplot}
\tdplotsetmaincoords{70}{0}
\begin{document}
\begin{tikzpicture}[scale=5,
declare function={tcrit(\x)=atan2(cos(\x)*sin(\tdplotmaintheta),cos(\tdplotmaintheta));% limit of visibility
w=.2;% width of the handle
}]
\pgfmathsetmacro{\myphi}{-30}% view angle
\pgfmathsetmacro{\myalpha}{asin(w)}% angle computed from the width of the band
\tdplotsetrotatedcoords{\myphi}{00}{0}
\pgfmathsetmacro{\tcrit}{tcrit(\myphi)}% critical angle
\begin{scope}[tdplot_rotated_coords,smooth,variable=\t]
\draw[top color=black,bottom color=gray!50!black]
plot[domain=0:\tcrit] ({sin(\myalpha)},{cos(\myalpha)*cos(\t)},{sin(\t)})
-- plot[domain=\tcrit:0] ({-sin(\myalpha)},{cos(\myalpha)*cos(\t)},{sin(\t)})
-- plot[domain=-\myalpha:\myalpha-360] ({sin(\t)},{cos(\t)},0);
\draw[ball color=gray]
plot[domain=90+\myphi:-\myalpha+180] ({sin(\t)},{cos(\t)},0) --
plot[domain=180:\tcrit] ({sin(\myalpha)},{cos(\myalpha)*cos(\t)},{sin(\t)})
-- plot[domain=\tcrit:180] ({-sin(\myalpha)},{cos(\myalpha)*cos(\t)},{sin(\t)})
-- plot[domain=180+\myalpha:270+\myphi] ({sin(\t)},{cos(\t)},0)
[tdplot_screen_coords]
arc[start angle=180,end angle=360,radius=1];
\end{scope}
\end{tikzpicture}
\end{document}
如果你使用,那么\pgfmathsetmacro{\myphi}{20}
你会得到: