问题如何在一组线条内绘画,我又有疑问了,我怎么才能把这些线像上图那样放出来呢:
基本上,我想在 a) 中绘制图像 b) c) 和 d) 红线。b) 线垂直切割图像,c) 线水平切割图像,d) 线圆形切割图像。谢谢!
编辑:图d)的代码如下:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage{pgfgantt}
\begin{document}
% isometric axes
\pgfmathsetmacro\xx{1/sqrt(2)}
\pgfmathsetmacro\xy{1/sqrt(6)}
\pgfmathsetmacro\zz{sqrt(2/3)}
\tikzset{isometric/.style={x={(-\xx cm,-\xy cm)},y={(\xx cm,-\xy cm)},z={(0cm,\zz cm)}}}
% parameters
\def\nc{24} % number of cogs (multiple of 4, at least 8)
\def\H {1} % total height
\def\h {0.25} % cog height
\def\R {2} % outer radius
\def\r {1.5} % inner radius
\pgfmathtruncatemacro\nw{\nc/4} % number of cog walls per quadrant
\pgfmathsetmacro\a {180/\nc} % step angle
\pgfmathsetmacro\is{135+2*\a} % inner part step
\pgfmathsetmacro\il{315-4*\a} % inner part last iteration
\pgfmathsetmacro\os{-45+2*\a} % outer part step
\pgfmathsetmacro\ol{135-4*\a} % outer part last iteration
\tikzset
{
inner/.style={fill=gray!30},
outer/.style={fill=gray!10},
cogs/.style= {fill=gray!50},
top/.style= {fill=gray!20},
cut/.style= {color=red!60, dashed},
}
\begin{tikzpicture}[x=0.75pt,y=0.75pt,yscale=1,xscale=1, isometric,line join=round,line cap=round]
% inner cogs side walls
\foreach\i in{-\nw,...,\nw}
{
\pgfmathsetmacro\j{4*\nw-\i}
\pgfmathsetmacro\k{6*\nw+\i}
\draw[cogs] (\a*\j:\R) -- (\a*\j:\r) --++ (0,0,\h) --++ (\a*\j:\R-\r) -- cycle;
\draw[cogs] (\a*\k:\R) -- (\a*\k:\r) --++ (0,0,\h) --++ (\a*\k:\R-\r) -- cycle;
}
% inner part
\draw[inner] (135:\r) foreach\i in {135,\is,...,\il}
{arc (\i:\i+\a:\r) --++ (0,0,\h) arc (\i+\a:\i+2*\a:\r) --++ (0,0,-\h)}
arc (315-2*\a:315-\a:\r) --++ (0,0,\h) arc (315-\a:315:\r) --++ (0,0, \H-\h)
arc (315:135:\r) -- cycle;
% outer cogs side walls
\foreach\i in{-\nw,...,\nw}
{
\pgfmathsetmacro\j{-\i+2*\nw}
\draw[cogs] (\a*\i:\R) -- (\a*\i:\r) --++ (0,0,\h) --++ (\a*\i:\R-\r) -- cycle;
\draw[cogs] (\a*\j:\R) -- (\a*\j:\r) --++ (0,0,\h) --++ (\a*\j:\R-\r) -- cycle;
}
% outer part
\draw[outer] (-45:\R) foreach\i in {-45,\os,...,\ol}
{arc (\i:\i+\a:\R) --++ (0,0,\h) arc (\i+\a:\i+2*\a:\R) --++ (0,0,-\h)}
arc (135-2*\a:135-\a:\R) --++ (0,0,\h) arc (135-\a:135:\R) --++ (0,0,\H-\h)
arc (135:-45:\R) -- cycle;
% top part
\draw[even odd rule,top] (0,0,\H) circle (\R) (0,0,\H) circle (\r);
\draw[even odd rule,cut] (0,0,\H) circle (0.95*\R);
\draw[even odd rule,cut] (0,0,\H) circle (0.90*\R);
\draw[even odd rule,cut] (0,0,\H) circle (0.85*\R);
\draw[even odd rule,cut] (0,0,\H) circle (0.80*\R);
\end{tikzpicture}
\end{document}
答案1
\documentclass[tikz, border=1cm]{standalone}
\begin{document}
% isometric axes
\pgfmathsetmacro\xx{1/sqrt(2)}
\pgfmathsetmacro\xy{1/sqrt(6)}
\pgfmathsetmacro\zz{sqrt(2/3)}
\tikzset{isometric/.style={x={(-\xx cm,-\xy cm)},y={(\xx cm,-\xy cm)},z={(0cm,\zz cm)}}}
% parameters
\def\nc{24} % number of cogs (multiple of 4, at least 8)
\def\H {1} % total height
\def\h {0.25} % cog height
\def\R {2} % outer radius
\def\r {1.5} % inner radius
\pgfmathtruncatemacro\nw{\nc/4} % number of cog walls per quadrant
\pgfmathsetmacro\a {180/\nc} % step angle
\pgfmathsetmacro\is{135+2*\a} % inner part step
\pgfmathsetmacro\il{315-4*\a} % inner part last iteration
\pgfmathsetmacro\os{-45+2*\a} % outer part step
\pgfmathsetmacro\ol{135-4*\a} % outer part last iteration
\tikzset
{
inner/.style={fill=gray!30},
outer/.style={fill=gray!10},
cogs/.style= {fill=gray!50},
top/.style= {fill=gray!20},
cut/.style= {color=red!60},
}
\begin{tikzpicture}[x=0.75pt,y=0.75pt,yscale=1,xscale=1, isometric,line join=round,line cap=round]
% inner cogs side walls
\foreach\i in{-\nw,...,\nw}
{
\pgfmathsetmacro\j{4*\nw-\i}
\pgfmathsetmacro\k{6*\nw+\i}
\draw[cogs] (\a*\j:\R) -- (\a*\j:\r) --++ (0,0,\h) --++ (\a*\j:\R-\r) -- cycle;
\draw[cogs] (\a*\k:\R) -- (\a*\k:\r) --++ (0,0,\h) --++ (\a*\k:\R-\r) -- cycle;
}
% inner part
\draw[inner] (135:\r) foreach\i in {135,\is,...,\il}
{arc (\i:\i+\a:\r) --++ (0,0,\h) arc (\i+\a:\i+2*\a:\r) --++ (0,0,-\h)}
arc (315-2*\a:315-\a:\r) --++ (0,0,\h) arc (315-\a:315:\r) --++ (0,0, \H-\h)
arc (315:135:\r) -- cycle;
% outer cogs side walls
\foreach\i in{-\nw,...,\nw}
{
\pgfmathsetmacro\j{-\i+2*\nw}
\draw[cogs] (\a*\i:\R) -- (\a*\i:\r) --++ (0,0,\h) --++ (\a*\i:\R-\r) -- cycle;
\draw[cogs] (\a*\j:\R) -- (\a*\j:\r) --++ (0,0,\h) --++ (\a*\j:\R-\r) -- cycle;
}
% outer part
\draw[outer] (-45:\R) foreach\i in {-45,\os,...,\ol}
{arc (\i:\i+\a:\R) --++ (0,0,\h) arc (\i+\a:\i+2*\a:\R) --++ (0,0,-\h)}
arc (135-2*\a:135-\a:\R) --++ (0,0,\h) arc (135-\a:135:\R) --++ (0,0,\H-\h)
arc (135:-45:\R) -- cycle;
% top part
\draw[even odd rule,top] (0,0,\H) circle (\R) (0,0,\H) circle (\r);
\begin{scope}
\clip (-45:\R) foreach\i in {-45,\os,...,\ol} %clip with same path as the outer drawing
{arc (\i:\i+\a:\R) --++ (0,0,\h) arc (\i+\a:\i+2*\a:\R) --++ (0,0,-\h)}
arc (135-2*\a:135-\a:\R) --++ (0,0,\h) arc (135-\a:135:\R) --++ (0,0,\H-\h)
arc (135:-45:\R) -- cycle;
\draw[cut] (-45:\R) ++(0,0, 0.8*\H) arc (-45:135:\R);
\draw[cut] (-45:\R) ++(0,0, 0.6*\H) arc (-45:135:\R);
\draw[cut] (-45:\R) ++(0,0, 0.4*\H) arc (-45:135:\R);
\draw[cut] (-45:\R) ++(0,0, 0.2*\H) arc (-45:135:\R);
\end{scope}
\begin{scope}
\clip (0,0, \H) circle (\r);
\clip (135:\r) foreach\i in {135,\is,...,\il} %clip with same path as the inner drawing
{arc (\i:\i+\a:\r) --++ (0,0,\h) arc (\i+\a:\i+2*\a:\r) --++ (0,0,-\h)}
arc (315-2*\a:315-\a:\r) --++ (0,0,\h) arc (315-\a:315:\r) --++ (0,0, \H-\h)
arc (315:135:\r) -- cycle;
\draw[cut] (-45:\r) ++(0,0, 0.8*\H) arc (135:-45:-\r);
\draw[cut] (-45:\r) ++(0,0, 0.6*\H) arc (135:-45:-\r);
\draw[cut] (-45:\r) ++(0,0, 0.4*\H) arc (135:-45:-\r);
\draw[cut] (-45:\r) ++(0,0, 0.2*\H) arc (135:-45:-\r);
\end{scope}
\end{tikzpicture}
\end{document}
答案2
c) 图像。只缺少最下面一行中的齿轮间隙中断。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\begin{document}
% isometric axes
\pgfmathsetmacro\xx{1/sqrt(2)}
\pgfmathsetmacro\xy{1/sqrt(6)}
\pgfmathsetmacro\zz{sqrt(2/3)}
\tikzset{isometric/.style={x={(-\xx cm,-\xy cm)},y={(\xx cm,-\xy cm)},z={(0cm,\zz cm)}}}
% parameters
\def\nc{24} % number of cogs (multiple of 4, at least 8)
\def\H {1} % total height
\def\h {0.25} % cog height
\def\R {2} % outer radius
\def\r {1.5} % inner radius
\pgfmathtruncatemacro\nw{\nc/4} % number of cog walls per quadrant
\pgfmathsetmacro\a {180/\nc} % step angle
\pgfmathsetmacro\is{135+2*\a} % inner part step
\pgfmathsetmacro\il{315-4*\a} % inner part last iteration
\pgfmathsetmacro\os{-45+2*\a} % outer part step
\pgfmathsetmacro\ol{135-4*\a} % outer part last iteration
\tikzset
{
inner/.style={fill=gray!30},
outer/.style={fill=gray!10},
cogs/.style= {fill=gray!50},
top/.style= {fill=gray!20},
cut/.style= {color=red!60, dashed},
}
\begin{tikzpicture}[x=0.75pt,y=0.75pt,yscale=1,xscale=1, isometric,line join=round,line cap=round]
% inner cogs side walls
\foreach\i in{-\nw,...,\nw}
{
\pgfmathsetmacro\j{4*\nw-\i}
\pgfmathsetmacro\k{6*\nw+\i}
\draw[cogs] (\a*\j:\R) -- (\a*\j:\r) --++ (0,0,\h) --++ (\a*\j:\R-\r) -- cycle;
\draw[cogs] (\a*\k:\R) -- (\a*\k:\r) --++ (0,0,\h) --++ (\a*\k:\R-\r) -- cycle;
}
% inner part
\draw[inner] (135:\r) foreach\i in {135,\is,...,\il}
{arc (\i:\i+\a:\r) --++ (0,0,\h) arc (\i+\a:\i+2*\a:\r) --++ (0,0,-\h)}
arc (315-2*\a:315-\a:\r) --++ (0,0,\h) arc (315-\a:315:\r) --++ (0,0, \H-\h)
arc (315:135:\r) -- cycle;
% outer cogs side walls
\foreach\i in{-\nw,...,\nw}
{
\pgfmathsetmacro\j{-\i+2*\nw}
\draw[cogs] (\a*\i:\R) -- (\a*\i:\r) --++ (0,0,\h) --++ (\a*\i:\R-\r) -- cycle;
\draw[cogs] (\a*\j:\R) -- (\a*\j:\r) --++ (0,0,\h) --++ (\a*\j:\R-\r) -- cycle;
}
% outer part
\draw[outer] (-45:\R) foreach\i in {-45,\os,...,\ol}
{arc (\i:\i+\a:\R) --++ (0,0,\h) arc (\i+\a:\i+2*\a:\R) --++ (0,0,-\h)}
arc (135-2*\a:135-\a:\R) --++ (0,0,\h) arc (135-\a:135:\R) --++ (0,0,\H-\h)
arc (135:-45:\R) -- cycle;
% top part
\draw[even odd rule,top] (0,0,\H) circle (\R) (0,0,\H) circle (\r);
\begin{scope}
\clip (\R,\R, \H) circle (1.5*\R);
\draw[even odd rule,cut] (0,0, 0.75*\H) circle (\R);
\draw[even odd rule,cut] (0,0, 0.5*\H) circle (\R);
\clip (\R,\R, \H) circle (1.2*\R);
\draw[even odd rule,cut] (0,0, 0.20*\H) circle (\R);
\end{scope}
\begin{scope}
\clip (0,0, \H) circle (\r);
\draw[even odd rule,cut] (0,0, 0.8*\H) circle (\r);
\draw[even odd rule,cut] (0,0, 0.6*\H) circle (\r);
\draw[even odd rule,cut] (0,0, 0.4*\H) circle (\r);
\draw[even odd rule,cut] (0,0, 0.2*\H) circle (\r);
\end{scope}
%\draw[even odd rule,cut] (0,0,\H) circle (0.95*\R);
%\draw[even odd rule,cut] (0,0,\H) circle (0.90*\R);
%\draw[even odd rule,cut] (0,0,\H) circle (0.85*\R);
%\draw[even odd rule,cut] (0,0,\H) circle (0.80*\R);
\end{tikzpicture}
\end{document}