MathGroup Archive 2012

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: hatched regions, shading, and fills

  • To: mathgroup at smc.vnet.net
  • Subject: [mg124317] Re: hatched regions, shading, and fills
  • From: Chris Young <cy56 at comcast.net>
  • Date: Mon, 16 Jan 2012 17:15:44 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <j0trq5$d2s$1@smc.vnet.net>

On 2011-07-29 08:42:45 +0000, Sam McDermott said:

> Hi,
>
> After looking over some old threads, it looks like there is no elegant
> way to add hatch marked regions in the interior of a graphic. This is
> regrettable, because it would really simplify things for my particular
> task right now.
>
> However, are there other easily accessed directives that might give a
> similar result? For instance, filling in a region with polka dots?
> Adding diagonal lines? Filling with a very simple texture?
>
> Any help is much appreciated,
> Thanks,
> Sam

The following will at least fill a triangle with hatch lines, green if
the orientation is positive, red if negative.
The mesh lines are plotted parallel to the first side.  A better way
might be to plot them perpendicular to an angle bisector of the
triangle.
It's a little slow, and it needs to have the hatch lines have the same
spacings no matter how the vertices of the triangle are moved around.

A notebook and screen shots are at:

http://home.comcast.net/~cy56/HatchLines.nb
http://home.comcast.net/~cy56/HatchLines1.png
http://home.comcast.net/~cy56/HatchLines2.png

Module[
 {
  x1, y1, x2, y2, x3, y3,
  orient
  },
 Manipulate[
  x1 = P[[1, 1]]; y1 = P[[1, 2]];
  x2 = P[[2, 1]]; y2 = P[[2, 2]];
  x3 = P[[3, 1]]; y3 = P[[3, 2]];

  orient = Sign[Chop[Det[\!\(\*
TagBox[
RowBox[{"(", "", GridBox[{
{"x1", "y1", "1"},
{"x2", "y2", "1"},
{"x3", "y3", "1"}
},
GridBoxAlignment->{
            "Columns" -> {{Center}}, "ColumnsIndexed" -> {},
             "Rows" -> {{Baseline}}, "RowsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.7]},
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]},
Offset[0.2]}, "RowsIndexed" -> {}}], "", ")"}],
Function[BoxForm`e$,
MatrixForm[BoxForm`e$]]]\)]]];
  Show[
   Graphics[
    {
     FaceForm[], EdgeForm[], Polygon[P],

     Blue,     Line[{P[[1]], P[[2]]}],
     Red,       Line[{P[[2]], P[[3]]}],
     Darker[Yellow, 0.3], Line[{P[[3]], P[[1]]}]
     }
    ],

   RegionPlot[
    And @@ (If[orient > 0, Positive, Negative] /@ {Det[( {
           {x1, x2, x},
           {y1, y2, y},
           {1, 1, 1}
          } )],  Det[( {
           {x2, x3, x},
           {y2, y3, y},
           {1, 1, 1}
          } )], Det[( {
           {x3, x1, x},
           {y3, y1, y},
           {1, 1, 1}
          } )] }),
    {x, -2, 2}, {y, -2, 2},

    ColorFunction -> (White &),
    BoundaryStyle -> None,
    Mesh -> Round[20 Norm[P[[2]] - P[[1]]], 1],
    MeshStyle -> (Green // If[orient > 0, #, Red] &),
    MeshFunctions -> {{x, y} \[Function] Det[( {
          {x2, x3, x},
          {y2, y3, y},
          {1, 1, 1}
         } )]},
    PlotPoints -> 50
    ],
   PlotRange -> 2,
   Axes -> True,
   GridLines -> Automatic
   ],

  {{P, {{0, 0}, {1, 0}, {1, 1}}}, Locator}
  ]
 ]




  • Prev by Date: Re: How to check whether an infinite set is closed under addition?
  • Next by Date: Re: How to check whether an infinite set is closed under addition?
  • Previous by thread: Re: hatched regions, shading, and fills
  • Next by thread: Re: without individual scaling?