Does the Mathematica graphics system have any concept of intersecting graphics? I've not found much in the documents so far. For example, if I want to show the intersection of two shapes:
Graphics[{Rectangle[], Disk[{0.2, 0}, .5]}]

I know I can use Opacity:
Graphics[{Opacity[0.8], Red, Rectangle[], Green, Disk[{0.2, 0}, .5]}]

But is there a way of specifying the colours of intersecting areas directly? It doesn't seem to be possible to 'address' the intersecting shapes any other way.
In the same vein, is is possible to 'extract' the graphical intersection of arbitrary shapes, without returning to the original geometry and calculating it? Could you obtain this type of entity easily given the above specification (these are just examples...!):

I think it might be easier with raster images, but am interested for now in vector graphics.
Answer
How about RegionPlot?
RegionPlot[
{
(x - 0.2)^2 + y^2 < 0.5 && 0 < x < 1 && 0 < y < 1,
(x - 0.2)^2 + y^2 < 0.5 && ! (0 < x < 1 && 0 < y < 1),
! ((x - 0.2)^2 + y^2 < 0.5) && 0 < x < 1 && 0 < y < 1
},
{x, -1, 1.5}, {y, -1, 1.5},
PlotStyle -> {Red, Yellow, Blue}
]

EDIT in response to Szabolcs's comment:
PointInPoly[{x_, y_}, poly_List] :=
Module[{i, j, c = False, npol = Length[poly]},
For[i = 1; j = npol, i <= npol, j = i++,
If[((((poly[[i, 2]] <= y) && (y <
poly[[j, 2]])) || ((poly[[j, 2]] <= y) && (y <
poly[[i, 2]]))) && (x < (poly[[j, 1]] -
poly[[i, 1]])*(y - poly[[i, 2]])/(poly[[j, 2]] -
poly[[i, 2]]) + poly[[i, 1]])), c = ¬ c];];
c]
(from an answer I gave in MathGroup)
RegionPlot[{
PointInPoly[{x, y}, {{1, 3}, {3, 4}, {4, 7}, {5, -1}, {3, -3}}] &&
PointInPoly[{x, y}, {{2, 2}, {3, 3}, {4, 2}, {0, 0}}],
PointInPoly[{x, y}, {{1, 3}, {3, 4}, {4, 7}, {5, -1}, {3, -3}}] &&
¬ PointInPoly[{x, y}, {{2, 2}, {3, 3}, {4, 2}, {0, 0}}],
¬ PointInPoly[{x, y}, {{1, 3}, {3, 4}, {4, 7}, {5, -1}, {3, -3}}] &&
PointInPoly[{x, y}, {{2, 2}, {3, 3}, {4, 2}, {0, 0}}]},
{x, 0, 6}, {y, -4, 8},
PlotPoints -> 100, PlotStyle -> {Red, Yellow, Blue}
]

Comments
Post a Comment