14
\documentclass[pstricks,border=12pt]{standalone}

\psset{unit=.25}
\def\Atom#1{%
\begin{pspicture}[dimen=m](-12,-12)(12,12)
    \pstVerb{/AA 1 5 atan def /RR 26 sqrt def}
    \pscustom[fillstyle=eofill,fillcolor=red,linearc=#1]
    {
            \pscircle{3}
            \moveto(5,-1)
            \psLoop{6}
            {
                    \translate(5,0)
                    \psline(0,-1)(4,-1)(4,1)(0,1)
                    \translate(-5,0)
                    \psarc(0,0){!RR}{!AA}{!60 AA sub}
                    \rotate{60}
            }
            \closepath
    }
\end{pspicture}}

\begin{document}
\Atom{.5}
\Atom{0}
\end{document}

What causes the strange output for nonzero linearc below?

Output for linearc=.5

enter image description here

Output for linearc=0

enter image description here

Edit

According to Werner's comment, it is related to precision issue. Is there a smart solution to solve it?

2 Answers2

9

If the current path have a point (\moveto, previous \psarc), then \psline also draw a line from the current point to its first coordinate. In theory both points are identical. However these points are calculated completely different, the end point of \psarc and the first point of \psline rotated by \rotate{60}. Therefore rounding errors cannot be avoided in practice. The result is a very tiny line, much smaller than the arc that linearc wants to draw.

Solution: Just drop the redundant point, the first point of \psline:

\documentclass[pstricks,border=12pt]{standalone}

\psset{unit=.25}
\def\Atom#1{%
\begin{pspicture}[dimen=m](-12,-12)(12,12)
    \pstVerb{/AA 1 5 atan def /RR 26 sqrt def}
    \pscustom[fillstyle=eofill,fillcolor=red,linearc=#1]
    {
            \pscircle{3}
            \moveto(5,-1)
            \psLoop{6}
            {
                    \translate(5,0)
                    \psline(4,-1)(4,1)(0,1)
                    \translate(-5,0)
                    \psarc(0,0){!RR}{!AA}{!60 AA sub}
                    \rotate{60}
            }
            \closepath
    }
\end{pspicture}}

\begin{document}
\Atom{.5}
\end{document}

Result

Heiko Oberdiek
  • 271,626
2

Drawing without atan, just a sin and even without trigonometry for small angles up to 12° (24 infact) without difference, example with 15° and a little gap. Drawing is done in one path.

  1. in pale red the exact solution;
  2. in blue the without trigo.

For 10° :

enter image description here

zoom :

enter image description here

For 15° (small gap) :

enter image description here

\documentclass[tikz,margin=2pt]{standalone}
\usetikzlibrary{calc}
\begin{document}

\def\Rex{5}
\def\Rin{3}
\def\Theeth{2}
\def\Angle{10}
\def\R{.3}
\pgfmathsetmacro\Lt{2*sin(\Angle)*\Rex}
\pgfmathsetmacro\L{2*\Rex*\Angle*3.14159/180}

\begin{tikzpicture}

%\clip (-5,2) rectangle (0,7) ;

% exact solution
% with trigonometry but whithout atan, just a sin
% in red

\fill[fill=red!25,,even odd rule]  (-\Angle:\Rex)
\foreach \i in {0,60,...,300} {
    --(-\Angle+\i:\Rex)
    --++(\i:\Theeth-\R) arc (-90+\i:0+\i:\R)
    --++(90+\i:\Lt-2*\R) arc (0+\i:90+\i:\R)
    --(\Angle+\i:\Rex) arc (\Angle+\i:60-\Angle+\i:\Rex)
} -- cycle (0,0) circle (\Rin);

% approximative solution without trigonometry
% if x is small sin(x) ~ x in radian

\draw[blue] (0,0) circle (\Rin) (-\Angle:\Rex)
\foreach \i in {0,60,...,300} {
    --(-\Angle+\i:\Rex)
    --++(\i:\Theeth-\R) arc (-90+\i:0+\i:\R)
    --++(90+\i:\L-2*\R) arc (0+\i:90+\i:\R)
    --(\Angle+\i:\Rex) arc (\Angle+\i:60-\Angle+\i:\Rex)
} -- cycle ;

\end{tikzpicture}
\end{document}
Tarass
  • 16,912