# Draw part of ring with non-zero thickness using PSTricks

Is there a command for drawing part of a ring with non-zero thickness using PSTricks?

I know of \psRing but this draws a full ring.

What I want is similar to \pswedge but without the part of the wedge closest to the 'center'.

Update

Here is what I have 'brewed up' myself:

\documentclass{article}

\def\ringSegment(#1,#2)#3#4#5#6{%
\psline(!#3 #5 cos mul #1 add #3 #5 sin mul #2 add)(!#4 #5 cos mul #1 add #4 #5 sin mul #2 add)
\psarc(#1,#2){#4}{#5}{#6}
\psline(!#4 #6 cos mul #1 add #4 #6 sin mul #2 add)(!#3 #6 cos mul #1 add #3 #6 sin mul #2 add)
\psarc(#1,#2){#3}{#5}{#6}
}

\begin{document}

\begin{pspicture}[showgrid=true](0,0)(3,3)
\ringSegment(-0.2,-0.2){2}{3}{30}{60}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=blue]{\ringSegment(-0.2,-0.2){2}{3}{30}{60}}
\end{pspicture}

\end{document}


It is almost as I want it but the filling is not correct; the inner-most part of the filling is alone a line segment instead of along an arc. Can anyone help me fix this?

Update 2

I got it now; the enclosed area needs to be drawn clockwise instead of anti-clockwise:

\def\ringSegment(#1,#2)#3#4#5#6{%
\psarc(#1,#2){#3}{#5}{#6}
\psline(!#3 #6 cos mul #1 add #3 #6 sin mul #2 add)(!#4 #6 cos mul #1 add #4 #6 sin mul #2 add)
\psarc(#1,#2){#4}{#5}{#6}
\psline(!#4 #5 cos mul #1 add #4 #5 sin mul #2 add)(!#3 #5 cos mul #1 add #3 #5 sin mul #2 add)
}

-
\psRing is defined in pst-news13. –  Werner Dec 22 '13 at 0:05
@Werner Exactly. :) It is in pstricks-add. –  Svend Tveskæg Dec 22 '13 at 0:08

You need to trace the bottom part of \ringSegment using \psarcn rather than \psarc. Below I've updated the \ringSegment macro to take an optional argument as well:

\documentclass{article}

\makeatletter
\newcommand{\ringSegment}[1][]{
\expandafter\ringSegment@\expandafter[#1]}
\def\ringSegment@[#1](#2,#3)#4#5#6#7{%
\pscustom[#1]{%
\psline(!#4 #6 cos mul #2 add #4 #6 sin mul #3 add)(!#5 #6 cos mul #2 add #5 #6 sin mul #3 add)% Left edge
\psarc(#2,#3){#5}{#6}{#7}% Upper arc
\psline(!#5 #7 cos mul #2 add #5 #7 sin mul #3 add)(!#4 #7 cos mul #2 add #4 #7 sin mul #3 add)% Right edge
\psarcn(#2,#3){#4}{#7}{#6}% Lower arc
}%
}
\makeatother

\begin{document}

\begin{pspicture}[showgrid=true](0,0)(3,3)
\ringSegment(-0.5,-0.2){2}{3}{30}{60}
\ringSegment[linestyle=none,fillstyle=solid,fillcolor=blue](-0.2,-0.2){2}{3}{30}{60}
\end{pspicture}

\end{document}


Use \psarc for anti-clockwise and \psarcn for clockwise oriented arcs. The notation is similar for both. See the pstricks documentation for more (section 7 Arcs, circles and ellipses).

You may also be interested in the pair \psellipticarc and \psellipticarcn.

You may also consider drawing a super-thick line segment using \psarc/\psarcn...

-

A recommended solution only for the best practitioners. The simplification not only makes the code much more readable but it also saves more keystrokes, which in turn, reduces the carbon emission.

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

\makeatletter
\newcommand{\ringSegment}[1][]{
\expandafter\ringSegment@\expandafter[#1]}
\def\ringSegment@[#1](#2,#3)#4#5#6#7{%
\rput(#2,#3){%
\pscustom[#1]{%
\psarc(0,0){#5}{#6}{#7}% Upper arc
\psarcn(0,0){#4}{#7}{#6}% Lower arc
\closepath
}}%
}
\makeatother

\begin{document}

\begin{pspicture}[showgrid=true](0,0)(3,3)
\ringSegment(-0.5,-0.2){2}{3}{30}{60}
\ringSegment[linestyle=none,fillstyle=solid,fillcolor=blue](-0.2,-0.2){2}{3}{30}{60}
\end{pspicture}

\end{document}


-
\documentclass{article}
\usepackage{pstricks}

\makeatletter
\def\ringSegment{\pst@object{ringSegment}}
\def\ringSegment@i(#1)#2#3#4#5{%
\begin@ClosedObj
\use@par
\pscustom{%
\psarc(#1){#3}{#4}{#5}% Upper arc
\psarcn(#1){#2}{#5}{#4}% Lower arc
\closepath
}\end@ClosedObj\ignorespaces}
\makeatother

\begin{document}

\begin{pspicture}[showgrid=true](0,0)(3,3)
\ringSegment(-0.5,-0.2){2}{3}{30}{60}
\ringSegment*[linecolor=blue](-0.2,-0.2){2}{3}{30}{60}
\end{pspicture}

\end{document}


or with the current pstricks-add.tex version from http://texnik.dante.de/tex/generic/pstricks-add/.

\documentclass[pstricks]{standalone}
\begin{document}

\begin{pspicture}[showgrid](-3,-3)(3,3)
\psRing(0,0)[30,60]{2}{3}
\psRing*[linecolor=red,opacity=0.4](0,0)[60,30]{2}{3}
\psRing[linecolor=blue](0,0)[200,250]{2}{3}
\end{pspicture}

\end{document}


-
+1 for the simplification. –  stalking isn't tolerated Dec 22 '13 at 12:05

Another version for Herbert's solution.

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

\makeatletter
\def\ringSegment{\pst@object{ringSegment}}
\def\ringSegment@i(#1)#2#3#4#5{{%
\use@par
\pscustom[origin={#1}]{%
\psarc(0,0){#3}{#4}{#5}% Upper arc
\psarcn(0,0){#2}{#5}{#4}% Lower arc
\closepath
}}\ignorespaces}
\makeatother

\begin{document}

\begin{pspicture}[showgrid=true](0,0)(3,3)
\ringSegment(-0.5,-0.2){2}{3}{30}{60}
\ringSegment[linestyle=none,fillstyle=solid,fillcolor=blue](-0.2,-0.2){2}{3}{30}{60}
\end{pspicture}

\end{document}


Its output is the same!

## Notes:

\psarc and \psarcn seem to be inconsistent with other graphic objects because (0,0) cannot be ignored for both of them.

If you insist on ignoring the origin, use the following.

\psellipticarc(#3,#3){#4}{#5}% Upper arc
\psellipticarcn(#2,#2){#5}{#4}% Lower arc

-