Graphics, Figures & TablesDrawing a Cogwheel

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
simo
Posts: 18
Joined: Thu Feb 04, 2010 4:27 pm

Drawing a Cogwheel

Post by simo »

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.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
Stefan Kottwitz
Site Admin
Posts: 10319
Joined: Mon Mar 10, 2008 9:44 pm

Drawing a Cogwheel

Post by Stefan Kottwitz »

Hi Simo,

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}
Stefan
LaTeX.org admin
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

Drawing a Cogwheel

Post by svend_tveskaeg »

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)
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Drawing a Cogwheel

Post by localghost »

svend_tveskaeg wrote:[…] The PSTricks wizard himself (aka. Herbert Voß) has answered a similar question on {TeX} SX.
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
User avatar
Stefan Kottwitz
Site Admin
Posts: 10319
Joined: Mon Mar 10, 2008 9:44 pm

Drawing a Cogwheel

Post by Stefan Kottwitz »

Yes, there's a very nice short way created by Alain Matthes - here two stacked wheels with different parameters as a demo:

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} 
Just vary the values arguments. Just for fun with a quick shading too:

Code: Select all

\draw[shade] \gear{18}{2}{2.4}{10}{2};
\path[shade] circle(2);
wheels.png
wheels.png (5.66 KiB) Viewed 11308 times
Stefan
LaTeX.org admin
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

Re: Drawing a cogwheel in pgf/tikz

Post by svend_tveskaeg »

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)
simo
Posts: 18
Joined: Thu Feb 04, 2010 4:27 pm

Drawing a Cogwheel

Post by simo »

Hey Stefan_K,

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
cog1.png (5.76 KiB) Viewed 11176 times
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

Drawing a Cogwheel

Post by svend_tveskaeg »

Maybe the package pst-spirograph (list of files) is useful. Unfortunately, it is not on CTAN.
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)
Post Reply