Graphics, Figures & Tables ⇒ Drawing a Cogwheel
Drawing a Cogwheel
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis
- Stefan Kottwitz
- Site Admin
- Posts: 10360
- Joined: Mon Mar 10, 2008 9:44 pm
Drawing a Cogwheel
sounds like you could do it with a
\foreach
loop in TikZ. However, you could use PSTricks with pdfLaTeX when you load it with the pdf
option:Code: Select all
\usepackage[pdf]{pstricks}
- svend_tveskaeg
- Posts: 478
- Joined: Sun Jul 12, 2009 5:31 am
Drawing a Cogwheel
-- Zapp Brannigan, Futurama (season 1, episode 4)
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Drawing a Cogwheel
You can find lots of solutions for PSTricks with PDFLaTeX also here in the forum archive. And also on {TeX} SX there is a nice and simple answer to the question.
Thorsten
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
- Stefan Kottwitz
- Site Admin
- Posts: 10360
- Joined: Mon Mar 10, 2008 9:44 pm
Drawing a Cogwheel
Code: Select all
\documentclass[11pt]{scrartcl}
\usepackage{tikz}
% #1 number of teeths
% #2 radius intern
% #3 radius extern
% #4 angle from start to end of the first arc
% #5 angle to decale the second arc from the first
\newcommand{\gear}[5]{%
\foreach \i in {1,...,#1} {%
[rotate=(\i-1)*360/#1] (0:#2) arc (0:#4:#2) {[rounded corners=1.5pt]
-- (#4+#5:#3) arc (#4+#5:360/#1-#5:#3)} -- (360/#1:#2)
}}
\begin{document}
\begin{tikzpicture}
\draw[thick] \gear{18}{2}{2.4}{10}{2};
\end{tikzpicture}
\end{document}
Code: Select all
\draw[shade] \gear{18}{2}{2.4}{10}{2};
\path[shade] circle(2);
- svend_tveskaeg
- Posts: 478
- Joined: Sun Jul 12, 2009 5:31 am
Re: Drawing a cogwheel in pgf/tikz

-- Zapp Brannigan, Futurama (season 1, episode 4)
Drawing a Cogwheel
though am supposed to read on the
\foreach
loop in the manual, I would appreciate your explanation on the \foreach
code used. It would help to learn faster.This is good progress, I got it and this is what I have now.
Code: Select all
\documentclass{scrartcl}
\usepackage{tikz}
% #1 number of teeths
% #2 radius intern
% #3 radius extern
% #4 angle from start to end of the first arc
% #5 angle to decale the second arc from the first
\newcommand{\gear}[5]{%
\foreach \i in {1,...,#1} {%
[rotate=(\i-1)*360/#1] (0:#2) arc (0:#4:#2) {[rounded corners=.8pt]
-- (#4+#5:#3) arc (#4+#5:360/#1-#5:#3)} -- (360/#1:#2)
}
}
\begin{document}
\begin{tikzpicture}[]
\draw[fill=red] \gear{11}{3}{3.35}{10}{2};
\path[fill=red] circle(3);
\draw[thick,double distance=2pt,fill=white] circle(2.35);
\end{tikzpicture}
\end{document}
- Attachments
-
- cog1.png (5.76 KiB) Viewed 11993 times
- svend_tveskaeg
- Posts: 478
- Joined: Sun Jul 12, 2009 5:31 am
Drawing a Cogwheel
-- Zapp Brannigan, Futurama (season 1, episode 4)