5

Consider the following.

Code

% lualatex filename.tex

\DocumentMetadata{}

\documentclass{article}

\usepackage{pst-eucl}

\def\maksimumB{\fpeval{2(1+3^(1/2))\radius} } \def\maksimumH{\fpeval{(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_{\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?

  • 2
    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 07 '13 at 06:27
  • @Werner Why haven't you voted for the others then? It seems a bit strange to close this question if the others were not closed, but okay. – Svend Tveskæg May 07 '13 at 06:29
  • (1) I may have been too late to the game for the others; (2) The others may have had major improvements to the code which I feel this one doesn't; (3) Your questions states that "you think" the code is somewhat messy" which it doesn't seem to me. Again, it's just my opinion. Others can vote to leave it open... – Werner May 07 '13 at 06:36
  • @SvendTveskæg Please explain/list what kind of improvements in PSTricks code, make it reachable to a wider audience for eg: non-pstricks users. ? I tried following your previous questions with the same pattern but miserably failed due to my ignorance in PSTricks and less informative nature. My opnion: It should be OP<--> multi users information transfer not only OP <--> Q answerers – texenthusiast May 07 '13 at 06:39
  • To all: Just close the question. This is exactly the same that goes on all the time for people like me when someone posts TikZ code. I'm not going to keep arguing my case; over and out. – Svend Tveskæg May 07 '13 at 06:43
  • @SvendTveskæg I have no rep to close your Q, I just made a kind suggestion. Don't despair I like your enthusiasm with PSTricks. Good luck, you can always vote to reopen as well. we are working as community not individuals. – texenthusiast May 07 '13 at 06:50
  • I don't despair, I just can't follow the arguments for closing it. – Svend Tveskæg May 07 '13 at 06:53
  • @SvendTveskæg: I just don't think the code can be improved that much. Herbert might have some magic to reveal a three-line masterpiece... who knows!? Two lines being taken up by the opening and closing of the pspicture environment. :) – Werner May 07 '13 at 06:57
  • 4
    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 07 '13 at 07: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 07 '13 at 08:17
  • 1
    Maybe I phrased my comment poorly, I'm sorry if it offended you. – Scott H. May 07 '13 at 08:41
  • @ScottH. You are saying that I don't want to learn PSTricks and just want Herbert to do my work for me. If that is not ignorance, I don't know what is. I'm not continuing this conversation with you from now on. – Svend Tveskæg May 07 '13 at 09:24
  • I think @ScottH.'s concern is about the same boilerplate commentary: I have some code, it's messy and I want to improve it. I also have wondered about this. –  May 07 '13 at 10:46
  • I think we can create a new tag named code-review for this kind of question. best-practice and code-review tags should be appropriate for this question. If it is not possible in TeX.SeX then the last resort is CodeReview.SeX. – kiss my armpit May 07 '13 at 12:15
  • @Bugbusters Idea is not bad, may be place it at meta.tex.sx for community discussion and consensus of tags. – texenthusiast May 07 '13 at 16:50
  • Svend: I didn't say that's what you were doing, only that at some point it will start to appear that way. I tried to make that clear in the comment. – Scott H. May 07 '13 at 17:05
  • 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 08 '13 at 01:32
  • Hi Downvoter, This flavour question/s are in discussion at meta. It would be wise to leave a comment and follow the meta links by @Werner and express your criticism/opinion if any and rethink on downvote. – texenthusiast May 08 '13 at 17:08

4 Answers4

7

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}
6

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}
  • 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 07 '13 at 07:11
  • put the \pstVerb into the pspicture environment. I'll change my code, see above. –  May 07 '13 at 07:12
2

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

Qrrbrbirlbel
  • 119,821
2

With tkz-euclide and no calculation (compass and ruler)

 \documentclass[a4paper]{scrartcl}
 \usepackage[usenames,dvipsnames,svgnames]{xcolor}
 \usepackage{tkz-euclide}
 \usetkzobj{all}     
 \definecolor{fondpaille}{cmyk}{0,0,0.1,0}   
 \tkzSetUpColors[background=fondpaille,text=Maroon]  

 \begin{document}
 \begin{tikzpicture}
  \tkzDefPoint(0,0){A}
  \tkzDefPoint(8,0){B}
  \tkzDefEquilateral(A,B)\tkzGetPoint{C}
   %first circle
  \tkzDefPointBy[projection= onto A--B](C)  \tkzGetPoint{Hc}
  \tkzDefLine[bisector](B,A,C) \tkzGetPoint{a}
  \tkzDefLine[bisector](A,Hc,C) \tkzGetPoint{hc}
  \tkzInterLL(A,a)(Hc,hc) \tkzGetPoint{Oa}
  \tkzDefPointBy[projection= onto A--B](Oa)  \tkzGetPoint{I}
   %second circle
  \tkzDefLine[bisector](C,B,A) \tkzGetPoint{b}
  \tkzDefLine[bisector](B,Hc,C) \tkzGetPoint{ha}
  \tkzInterLL(B,b)(Hc,ha) \tkzGetPoint{Ob}
  \tkzDefPointBy[projection= onto A--B](Ob)  \tkzGetPoint{J} 
   %third circle
  \tkzDefPointBy[projection= onto A--C](B)  \tkzGetPoint{Hb}
  \tkzDefLine[bisector](C,Hb,B) \tkzGetPoint{hb}
  \tkzInterLL(C,Hc)(Hb,hb) \tkzGetPoint{Oc}
  \tkzDefPointBy[projection= onto C--B](Oc)  \tkzGetPoint{K}
   %drawing
  \tkzDefMidPoint(C,B) \tkzGetPoint{E}  
  \tkzDrawPolygon[color=Maroon](A,B,C)
  \tkzDrawPolygon[color=Maroon,dashed](Oa,Ob,Oc)
  \tkzDrawCircle(Oa,I)    
  \tkzDrawCircle(Ob,J)   
  \tkzDrawCircle(Oc,K)
  \tkzDrawPoints(Oa,Ob,Oc,A,B,C)
   %labels
  \tkzLabelPoints[left](Oa,A)
  \tkzLabelPoints[right](Ob,B)
  \tkzLabelPoints[above](Oc,C)  \end{tikzpicture}                                                                   
 \end{document}

enter image description here

Alain Matthes
  • 95,075