Graphics, Figures & Tables ⇒ Drawing a Cogwheel
Drawing a Cogwheel
In PSTricks its known as a cogwheel. My aim is to draw a circle with the outer border as a cogwheel and the inside border as a normal smooth curve, may be shade the area between. If I use PSTricks I'm required to use ps2pdf. But this will conflict with other parts and packages that need pdfLaTeX. An idea is appreciated.
NEW: TikZ book now 40% off at Amazon.com for a short time.
- Stefan Kottwitz
- Site Admin
- Posts: 10319
- Joined: Mon Mar 10, 2008 9:44 pm
Drawing a Cogwheel
Hi Simo,
sounds like you could do it with a
Stefan
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}
LaTeX.org admin
- svend_tveskaeg
- Posts: 478
- Joined: Sun Jul 12, 2009 5:31 am
Drawing a Cogwheel
Just as a supplementation to Stefan's answer. The PSTricks wizard himself (aka. Herbert Voß) has answered a similar question on {TeX} SX.
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)
-- 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
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
- Stefan Kottwitz
- Site Admin
- Posts: 10319
- Joined: Mon Mar 10, 2008 9:44 pm
Drawing a Cogwheel
Yes, there's a very nice short way created by Alain Matthes - here two stacked wheels with different parameters as a demo:
Just vary the values arguments. Just for fun with a quick shading too:
Stefan
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);
LaTeX.org admin
- svend_tveskaeg
- Posts: 478
- Joined: Sun Jul 12, 2009 5:31 am
Re: Drawing a cogwheel in pgf/tikz
Nice. That could come in handy for me as well. 

``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)
-- Zapp Brannigan, Futurama (season 1, episode 4)
Drawing a Cogwheel
Hey Stefan_K,
though am supposed to read on the
This is good progress, I got it and this is what I have now.
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 11177 times
- svend_tveskaeg
- Posts: 478
- Joined: Sun Jul 12, 2009 5:31 am
Drawing a Cogwheel
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)
-- Zapp Brannigan, Futurama (season 1, episode 4)