Colouring intersection of circles.

Denis Girou Denis.Girou at idris.fr
Wed Nov 17 19:12:14 CET 1999


-----------------------------------------------------------------------------
This is the PSTricks mailing list, devoted to discussions about computational
graphics in (La)TeX using the PSTricks package from Timothy van Zandt.
For help using this mailing list, see instructions at the end of message.
-----------------------------------------------------------------------------

>>>>> "Suresh.Kumar" == Suresh Kumar R <sudhas at md3.vsnl.net.in> writes:

    Suresh.Kumar> I have two circles which overlapp. I want to shade the intersecting
    Suresh.Kumar> region. How to do it.

  This is easy using the clipping mechanism (see paragraph 28 of the manual).

    Suresh.Kumar> Can the problem be extended to say 3 or 4 cirlces or some other shapes?

  Yes, this is the same thing. Here is an example:

\documentclass{article}

\usepackage{pstricks}

\pagestyle{empty}

\begin{document}

\psset{subgriddiv=0}

\begin{pspicture}(5,5)\psgrid
  \newcommand{\SurfaceA}{\pscircle(1,1){1}}
  \newcommand{\SurfaceB}{\pscircle(2.5,3){2}}
  \SurfaceA\SurfaceB
  \begin{psclip}{\SurfaceA}
    \psset{fillstyle=crosshatch}
    \SurfaceB
  \end{psclip}
\end{pspicture}
\hfill
\begin{pspicture}(5,5)\psgrid
  \newcommand{\SurfaceA}{\psframe(1.5,0.5)(3.8,4.8)}
  \newcommand{\SurfaceB}{\psellipse(2,3.5)(1.5,1)}
  \newcommand{\SurfaceC}{\pscircle(3.5,3){1.5}}
  \newcommand{\SurfaceD}{\psdiamond(2.5,3)(2,1)}
  \SurfaceA\SurfaceB\SurfaceC\SurfaceD
  \begin{psclip}{\SurfaceA\SurfaceB\SurfaceC\SurfaceD}
    \psset{fillstyle=solid,fillcolor=red}
    \SurfaceA
  \end{psclip}
\end{pspicture}

\end{document}

  A more difficult question, but useful too, is how to compute automatically
the intersected colors, for instance using additive color synthesis. I give
long time ago a solution for the simple case of two surfaces
(see http://tug.org/applications/PSTricks/Various/ ), but it use at this time
the PSTricks color scheme and not the standard LaTeX one, and, more important,
the question to generalize it to any number of surfaces is a lot more
difficult.

  In fact, there was such discussion this summer in the french TeX newsgroup
(fr.comp.text.tex), starting from a question of Manuel Luque of how to draw in
PSTricks and MetaPost the classical graphic of the additive synthesis from the
RGB circles. It had appeared that this is a very pedagogical problem, starting 
from the basic but poor solution, to be able to generalize it to any number
of any kind of surfaces. At this time, we planned with Manuel Luque to write
a pedagocical paper showing different solutions, and explaining how and why
they are each time more powerful than the previous ones. It was also an
occasion to show non trivial PSTricks programming technics on a small
problem. At this time, I wrote also a solution for the general - and
difficult, but perhaps that it exist simplest solutions than mine - case,
with any number of surfaces.

  But, in fact, I switch to other things when 80 % of the all work was done.
I will try at least to finish soon the paper with Manuel Luque, as I think it
will be interesting for all people who want to learn more, not only on
PSTricks current usage, but on special programming technics.

    Suresh.Kumar> I saw a similar situation described in the Metapost manual, but in that
    Suresh.Kumar> example the two circles where placed one is below the other. I have
    Suresh.Kumar> circles shifted horizontally and the same code doesnot work.

    Suresh.Kumar> I think I fail to understand the buildcycle macro. But any other easier
    Suresh.Kumar> ways?

  The MetaPost mailing list <metafont at ens.fr> - I think that the administrative
interface is at <listserv at ens.fr> - (or even the comp.text.tex newsgroup)
is obviously better suited for MetaPost questions...

D.G.

-----------------------------------------------------------------------------
The list interface (subscription, information, access to the archives) is on:
http://www.tug.org/cgi-bin/lwgate/pstricks
Otherway to unsubscribe, send mail to pstricks-request at mail.tug.org
with a blank subject and in body the line unsubscribe <email-address>
-----------------------------------------------------------------------------



More information about the PSTricks mailing list