Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Consider the following.

Code

% pdflatex -shell-escape test.tex

\documentclass{article}

\usepackage{auto-pst-pdf,pst-eucl}
\usepackage{expl3}

\ExplSyntaxOn
  \cs_new_eq:NN \calc \fp_eval:n
\ExplSyntaxOff

\def\maksimumB{\calc{2*(1+3^(1/2))*\radius} }
\def\maksimumH{\calc{(3+3^(1/2))*\radius} }
\def\Angle[#1]#2#3#4{\pstMarkAngle{#2}{#3}{#4}{#1$60^{\circ}$}}

\begin{document}

\def\radius{21.5 }
\psset{unit=0.07cm}
\begin{pspicture}(\maksimumB,\maksimumH)
 \pnodes{P}(0,0)%
           (\maksimumB,0)%
           (!\maksimumB 2 div \maksimumH)
 \pspolygon(P0)(P1)(P2)
 \pnodes{C}(!3 sqrt \radius mul \radius)%
           (!2 3 sqrt add \radius mul \radius)%
           (!\maksimumB 2 div 1 3 sqrt add \radius mul)
 \pscircle(C0){\radius}
 \pscircle(C1){\radius}
 \pscircle(C2){\radius}
 \multido{\iA=0+1,\iB=1+1,\r=210+120}{3}{%
   \psdot(C\iA)
   \uput[\r](C\iA){$C_{\iB}$}
 }
\psset{%
  linestyle=dotted,%
  dotsep=1.5pt,%
  LabelSep=9,%
  MarkAngleRadius=5%
}
 \Angle[\footnotesize]{P2}{P1}{P0}
 \Angle[\footnotesize]{P1}{P0}{P2}
 \Angle[\footnotesize]{P0}{P2}{P1}
\psset{%
  LabelSep=7,%
  MarkAngleRadius=3%
}
 \pspolygon(C0)(C1)(C2)
 \Angle[\scriptsize]{C1}{C0}{C2}
 \Angle[\scriptsize]{C0}{C2}{C1}
 \Angle[\scriptsize]{C2}{C1}{C0}
\end{pspicture}

\end{document}

Output

output

Question

I have the desired output but the code is somewhat messy, I think; can anyone help me simplify if?

share|improve this question
1  
My opinion: I'm not entirely sure how helpful this question would be to a wider audience (including many of the others posed this way). Voting to close as TL. –  Werner May 7 '13 at 6:27
3  
You've asked at least a dozen of these, all with the same boilerplate commentary. At some point, people will start to doubt the sincerity of the questions (i.e do you want to learn how to improve the code yourself, or do you just want someone else to do it for you). It looks like you're getting close to that point. I'm not expressing an opinion one way or the other, just rationalizing the close votes if you're confused by them. –  Scott H. May 7 '13 at 7:47
2  
No need for name calling, you mentioned that you didn't understand the close votes (none of which were me) so I gave my take on it. I'm not sure what you find ignorant about that. –  Scott H. May 7 '13 at 8:17
1  
Maybe I phrased my comment poorly, I'm sorry if it offended you. –  Scott H. May 7 '13 at 8:41
1  
@SvendTveskæg: To add to this discussion I've posted a question on Meta: Tagging “Please improve my code” posts. Also, a question that was just posted here has a similar flavour to yours. However, in my opinion it has a reach to a wider audience, since it references styles for chapter pages: Code improvement and suggestions in template. Users can take the code and update it to their liking. Your post is particular to a triangle with 3 balls in it and doesn't scale to something larger/more abstract. –  Werner May 8 '13 at 1:32

3 Answers 3

up vote 5 down vote accepted

marking the angles is the same. Putting the origin in the middle of the base also simplifies the code:

\documentclass{article}
\usepackage{auto-pst-pdf,pst-eucl}

\begin{document}

\psset{unit=0.5mm}
\def\radius{21.5 }
\newlength\Radius \Radius=\radius\psunit
\begin{pspicture}(-3\Radius,0)(3\Radius,5\Radius)
\pstVerb{
  /maxB 2 dup 3 sqrt mul add \radius mul 2 div def
  /maxH 3 dup sqrt add \radius mul def }
\pnodes{P}(!maxB neg 0)(!maxB 0)(!0 maxH)
\pspolygon(P0)(P1)(P2)
\pnodes{C}(!\radius neg \radius)(\radius,\radius)(!0 1 3 sqrt add \radius mul)
\pscircle(C0){\Radius}\pscircle(C1){\Radius}\pscircle(C2){\Radius}
\pspolygon[showpoints,linestyle=dotted](C0)(C1)(C2)
\uput[225](C0){C1}\uput[-45](C1){C2}\uput[90](C2){C3}
\end{pspicture}

\end{document}

enter image description here

with the current pstricks.tex you can also calculate coordinates as P(+{algebraic},{algebraic}). The + is the identifier for the special handling:

\psset{unit=0.5mm}
\def\radius{21.5 }
\newlength\Radius \Radius=\radius\psunit
\begin{pspicture}(-3\Radius,0)(3\Radius,5\Radius)
\pnodes{P}(+{-(1+sqrt(3))*\radius},0)(+{(1+sqrt(3))*\radius},0)%
  (+{0},{(3+sqrt(3))*\radius})
\pspolygon(P0)(P1)(P2)
\pnodes{C}(!\radius neg \radius)(\radius,\radius)(!0 1 3 sqrt add \radius mul)
\pscircle(C0){\Radius}\pscircle(C1){\Radius}\pscircle(C2){\Radius}
\pspolygon[showpoints,linestyle=dotted](C0)(C1)(C2)
\uput[225](C0){C1}\uput[-45](C1){C2}\uput[90](C2){C3}
\end{pspicture}
share|improve this answer
    
code does not work with pdflatex. Normally auto-pst-pdf by [pdf] option works right ? I know it works with xelatex and latex->dvips->ps2pdf –  texenthusiast May 7 '13 at 7:11
    
put the \pstVerb into the pspicture environment. I'll change my code, see above. –  Herbert May 7 '13 at 7:12
    
Thank you, Herbert! –  Svend Tveskæg May 7 '13 at 8:08

Without TikZ.

enter image description here

\documentclass[pstricks,border=6pt]{standalone}
\SpecialCoor
\usepackage{fp}
\FPset\RR{2}% circle radius

\FPeval\XX{RR*root(2,3)}
\FPeval\RX{XX+RR}
\FPeval\Width{2*RX}
\FPeval\Height{RX*root(2,3)}

\def\Atom#1{%
    \pscircle(\XX,\RR){\RR}
    \psline(\RX;60)(0,0)(\RX,0)
    \bgroup
    \psset{linestyle=dashed}
    \psarc(0,0){15pt}{0}{60}
    \rput{*0}(25pt;30){$60^\circ$}
    \rput(\XX,\RR){%    
        \psline(\RR;60)(0,0)(\RR,0)
        \psarc(0,0){15pt}{0}{60}
        \qdisk(0,0){3pt}
        \rput{*0}(12pt;-150){$C_#1$}
        \rput{*0}(25pt;30){$60^\circ$}}
    \egroup
    \ignorespaces
}

\begin{document}
\begin{pspicture}(\Width,\Height)
    \Atom{1}
    \rput{120}(\Width,0){\Atom{2}}
    \rput{-120}(\RX,\Height){\Atom{3}}
\end{pspicture}
\end{document}

How it works:

enter image description here

\documentclass{beamer}

\usepackage{pstricks}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{pspicture}
\PreviewBorder=12pt\relax

\SpecialCoor
\usepackage{fp}
\FPset\RR{2}% circle radius

\FPeval\XX{RR*root(2,3)}
\FPeval\RX{XX+RR}
\FPeval\Width{2*RX}
\FPeval\Height{RX*root(2,3)}

\def\Atom#1{%
    \pscircle(\XX,\RR){\RR}\pause
    \psline(\RX;60)(0,0)(\RX,0)\pause
    \bgroup
    \psset{linestyle=dashed}
    \psarc(0,0){15pt}{0}{60}
    \rput{*0}(25pt;30){$60^\circ$}\pause
    \rput(\XX,\RR){%    
        \psline(\RR;60)(0,0)(\RR,0)\pause
        \psarc(0,0){15pt}{0}{60}\pause
        \qdisk(0,0){3pt}
        \rput{*0}(12pt;-150){$C_#1$}
        \rput{*0}(25pt;30){$60^\circ$}\pause}
    \egroup
    \ignorespaces
}

\begin{document}
\begin{frame}
\begin{pspicture}(\Width,\Height)
    \Atom{1}
    \rput{120}(\Width,0){\Atom{2}}
    \rput{-120}(\RX,\Height){\Atom{3}}
\end{pspicture}
\end{frame}
\end{document}
share|improve this answer
    
The 19th frame is identical to the 18th one. But I am too lazy to remove the 19th one. :-) –  Who is crazy first May 7 '13 at 8:44
1  
This is a really elegant solution! I'll use this one instead of Herbert's, I think. –  Svend Tveskæg May 7 '13 at 9:26
    
Hmm. It is as if the circles are not touching each other; there seems to be a tiny gab, but I'm not sure. –  Svend Tveskæg May 7 '13 at 11:01
    
@SvendTveskæg: You can change the dimen from outer (default) to middle for \pscircle. –  Who is crazy first May 7 '13 at 11:02
    
Spot on. Thank you. –  Svend Tveskæg May 7 '13 at 11:08

Just for fun with TikZ and the angles library from the CVS version.

Code

\documentclass[tikz]{standalone}
\usetikzlibrary{angles}
\begin{document}
\begin{tikzpicture}[x=7cm, y=7cm, thick, line join=round,
  dots/.style={dash pattern=on 1\pgflinewidth off 2\pgflinewidth},
  dot/.style={circle,fill,draw,inner sep=+0pt, minimum size=+2pt}]
\pgfmathsetmacro\r{.5/(1+1/tan 30)}
\pgfmathsetmacro\vB{2*\r}
\draw (0,0) coordinate (n-0) -- ++ (0:1) coordinate (n-1)
                             -- ++ (120:1) coordinate (n-2) -- cycle;
\foreach \a/\b/\c[count=\cnt from 0] in {1/\vB/\vB, \vB/1/\vB, \vB/\vB/1}
  \draw (barycentric cs:n-0=\a,n-1=\b,n-2=\c) node[dot] (C-\cnt) {}
        node[anchor=30+120*\cnt] {$C_{\pgfmathprint{int(\cnt+1)}}$} circle [radius=\r];
\draw[dots] (C-0) -- (C-1) -- (C-2) -- (C-0);
\foreach \cnt[evaluate={\pCnt=int(Mod(\cnt-1,3)); \nCnt=int(Mod(\cnt+1,3));}] in {0,...,2}
  \path[nodes={draw, dots, angle radius=+10pt, angle eccentricity=1.8,
               pic text=$\scriptstyle60^\circ$, pic text options={draw=none}}]
   pic {angle=C-\nCnt--C-\cnt--C-\pCnt} pic {angle=n-\nCnt--n-\cnt--n-\pCnt};
\end{tikzpicture}
\end{document}

Output

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.